if I've string like
"{ partner_name = test_partner}" OR " { partner_name : test_partner }
its an example string will be very complex with several special characters included like =, [ , ] , { , }
what will be the best way to convert it into a python object - so I can process it
I tried with eval but it requires " ' " for string, but how can we…
I built a very simple addition calculator in python:
#This program will add two numbers entered in by the user
print "Welcome!"
num1 = input("Please enter in the first number to be added.")
num2 = input("Please enter in the second number to be added.")
sum = num1 + num2
print "The sum of the two numbers entered is: ", sum
I haven't setup…
There is a snippet of code that I would like to copy and paste into my Python interpreter. Unfortunately due to Python's sensitivity to whitespace it is not straightforward to copy and paste it a way that makes sense. (I think the whitespace gets mangled) Is there a better way? Maybe I can load the snippet from a file.
This is just an small…
Hi,
I have a bunch of C macros the operation of which I need to simulate in python. I saw some pointers to pygccxml or ctypeslib etc. Are these the ways to go ? Or is there something out there that is better ?
The C macros if and when they change, I would like the python implementation to be auto generated rather than having to make manual…
Hi..:)
For documentation and presentation purposes, we often find professionals/students creating SRS, coding guidelines etc. for these things there is some kind of a checklist which one could use to appropriately match what could relate to a specific case and accordingly one does a documentation for each. On those grounds could you please…
I am trying to log into my table called acounts using MySQLdb in Python, but it does not work for me. I keep getting my message "Not Logged In". Here is my code:
database = MySQLdb.connect("127.0.0.1", "root", "pswd", "Kazzah")
cursor = database.cursor()
cursor.execute("SELECT * FROM Accounts WHERE Email=%s AND Password=%s", (_Email,…
Hi,
I've a python script which works just as it should but I need to write the time for the execution. I've gooled that I should use timeit but I can't seem to get it to work.
My Python script looks like this:
import sys
import getopt
import timeit
import random
import os
import re
import ibm_db
import time
from string import…
I have the following task:
Input:
A 3D scene comprised of a set of cuboids. Could be broken down to a set of triangles.
A description of a camera: position, direction, focal length.
Output: 2D wire frame projection of the scene as a set of lines. Important: Hidden lines removal should have been applied.
Platform: Web app…
I am looking for a way to control a browser from Python, i.e. fill out form fields and submit them, possibly call JS functions. I've looked around a bit, but as far as I could see PyWebKitGtk only lets you show the browser as a GUI element, not interface with it.
Is there a way to do this easily?
I wrote my program logic…
Is there a way to execute python code in a browser, other than using Jython and an applet?
The execution does not have to deal with anything related to graphics. For example, just sum all the digits of a binary 1Gb file (chosen by the browser user) and then return the result to the server.
I am aware that python can be…
I am currently writing an app in python that needs to generate large amount of random numbers, FAST. Currently I have a scheme going that uses numpy to generate all of the numbers in a giant batch (about ~500,000 at a time). While this seems to be faster than python's implementation. I still need it to go faster. Any…
In python you may have a function definition:
def info(object, spacing=10, collapse=1)
which could be called in any of the following ways:
info(odbchelper)
info(odbchelper, 12)
info(odbchelper, collapse=0)
info(spacing=15, object=odbchelper)
thanks to python's…
Hi, I have a python subprocess call which I would like to link up to three pipes (two standard in and one standard out). I know that there is only one /dev/stdin, but there's all those other devices in /dev I don't know about, and don't know of any python os, sys or subprocess modules that will utilise them…
I'm working on a Python script that transforms this:
foo
bar
Into this:
[[Component foo]]
[[bar]]
The script checks (per input line) if the page "Component foo" exists. If it exists then a link to that page is created, if it doesn't exist then a direct link is created.
The problem is that I need a…
In Python IDLE Shell it seems I cannot use a compound conditional expression and a while loop. I tried it within brackets too.
k=0
m=0
while k<10 & m<10:
print k
k +=1
m+=1
If I write
while k<10:
print k
k+=1
This does work. Is there a way I could achieve the…
I'm about to port a smallish library from Java to Python and wanted some advice (smallish ~ a few thousand lines of code). I've studied the Java code a little, and noticed some design patterns that are common in both languages. However, there were definitely some Java-only idioms (singletons, etc)…
Hi all,
I'm having a problem with processing a largeish file in Python. All I'm doing is
f = gzip.open(pathToLog, 'r')
for line in f:
counter = counter + 1
if (counter % 1000000 == 0):
print counter
f.close
This takes around 10m25s just to open the file, read the…
We are currently installing the latest version of Django and Python on IIS6. We have followed the instructions on the following site:
http://code.djangoproject.com/wiki/DjangoOnWindowsWithIISAndSQLServer
We are receiving a 403 error when trying to access our Django application via the IIS…
Hi,
Would it be possible to create a class interface in python and various implementations of the interface.
Example: I want to create a class for pop3 access (and all methods etc.). If I go with a commercial component, I want to wrap it to adhere to a contract.
In the future, if I want…
Hi everybody,
I'm using the python logging module with the "native"
configuration file support (config.fileconfig) as describe in the documentation here :
http://docs.python.org/library/logging.html (see the logging.conf file)
I was wondering if it's possible to supply a tabulated data…
I have code similar to the following running in a script:
try:
s = ftplib.FTP('xxx.xxx.xxx.xxx','username','password')
except:
print ('Could not contact FTP serer')
sys.exit()
IF the FTP site is inaccessible, the script almost seems to 'hang' ... It is taking about 75…
Sorry for the trivial question, but I can't find this infomation from the manual. I am developping a module for python using C api; how can I create a variabile that is seen as global from python? For example if my module is module I want to create a variable g that do this job:
…
I have a python function that has a deterministic result. It takes a long time to run and generates a large output:
def time_consuming_function():
# lots_of_computing_time to come up with the_result
return the_result
I modify time_consuming_function from time to time,…