content stringlengths 85 101k | title stringlengths 0 150 | question stringlengths 15 48k | answers list | answers_scores list | non_answers list | non_answers_scores list | tags list | name stringlengths 35 137 |
|---|---|---|---|---|---|---|---|---|
Q:
AWS - Running webservice - Cherrypy + Python
I have a linux box (Ubuntu 10.10 server edition) in ec2. I have written a web service using cherrypy framework. Let's say this is the code that I have written.
import sys
sys.path.insert(0,'cherrypy.zip')
import cherrypy
from cherrypy import expose
class Service:
... | AWS - Running webservice - Cherrypy + Python | I have a linux box (Ubuntu 10.10 server edition) in ec2. I have written a web service using cherrypy framework. Let's say this is the code that I have written.
import sys
sys.path.insert(0,'cherrypy.zip')
import cherrypy
from cherrypy import expose
class Service:
@expose
def index(self):
return 'Hello... | [
"The cherrypy.quickstart function takes a config argument, which can be a dict, an open configuration file, or a path to a configuration file. I favor using a path to a configuration file because that minimizes the hardcoding of settings that you might prefer to control from a startup script.\nIn addition, since y... | [
1
] | [] | [] | [
"amazon_ec2",
"cherrypy",
"python",
"web_services"
] | stackoverflow_0005514553_amazon_ec2_cherrypy_python_web_services.txt |
Q:
Why and how does python truncate numerical data?
Am dealing with two variables here, but confused because their values seem to be changing (they loose precision) when I want to send them as URL parameters as they are.
Look at this scenario as I reproduce it here from the python interpreter:
>>> lat = 0.33245794180... | Why and how does python truncate numerical data? | Am dealing with two variables here, but confused because their values seem to be changing (they loose precision) when I want to send them as URL parameters as they are.
Look at this scenario as I reproduce it here from the python interpreter:
>>> lat = 0.33245794180134
>>> long = 32.57355093956
>>> lat
0.33245794180133... | [
"In general if you use '%.14f' % lat, you are LOSING PRECISION.\nTo get full precision from a float, use repr().\nExample:\n>>> lat = 1/3.\n>>> lat\n0.3333333333333333\n>>> str(lat).count('3')\n12\n>>> ('%.14f' % lat).count('3')\n14\n>>> repr(lat).count('3')\n16\n>>>\n\nBy the way, you are using an old Python. \n>>... | [
4,
3,
2,
0
] | [] | [] | [
"floating_accuracy",
"python",
"serialization"
] | stackoverflow_0005728978_floating_accuracy_python_serialization.txt |
Q:
How do I convert a string into an algebraic or transcendental function in Python?
This code is a wxglade code & it takes the input of a text box whis is a algebraic or transcendental function
def event_2(self, event): # wxGlade: application.<event_handler>
#print "Event handler `event_2' not implemented!"... | How do I convert a string into an algebraic or transcendental function in Python? | This code is a wxglade code & it takes the input of a text box whis is a algebraic or transcendental function
def event_2(self, event): # wxGlade: application.<event_handler>
#print "Event handler `event_2' not implemented!"
#event.Skip()
equationString = self.text_ctrl_1.GetValue()
function = ... | [
"Whatever Python code you've put in text_ctrl_1 refers to a variable d that wasn't defined. Python does not understand algebra or symbolic math; if you pass a string like x = y + 3 to eval and either x or y are not defined Python will throw an error.\nThere are, however, libraries to do symbolic math in Python. If ... | [
3
] | [] | [] | [
"python",
"wxpython"
] | stackoverflow_0005752375_python_wxpython.txt |
Q:
Using django exclude filter problem with empty m2m field
The queryset I've constructed is incorrectly leaving out some items. I have three models in Django:
class Case(models.Model):
agents = models.ManyToManyField('UserProfile', related_name='agent_of', blank=True, null=True)
organization = models.Foreig... | Using django exclude filter problem with empty m2m field | The queryset I've constructed is incorrectly leaving out some items. I have three models in Django:
class Case(models.Model):
agents = models.ManyToManyField('UserProfile', related_name='agent_of', blank=True, null=True)
organization = models.ForeignKey(Organization, related_name='case_org')
class UserProfil... | [
"The question is a bit unclear but does this query not work to get all cases that aren't assigned to that user?\nCase.objects.exclude(agents=request.user)\n\nIf you are trying to get cases belonging to user's organization AND not assigned to him OR NOT unassigned to anybody this should work.\nCase.objects.filter(Q(... | [
1
] | [] | [] | [
"django",
"orm",
"python"
] | stackoverflow_0005751987_django_orm_python.txt |
Q:
modify text file
I need to modify all files that has a ".txt" extension within a directory in the following way:
remove all text lines beginning with the line that starts with "xxx" and the line that ends with "xxx", inclusive.
I know how to do this in Java or C++, but can someone show me a simple script that can ... | modify text file | I need to modify all files that has a ".txt" extension within a directory in the following way:
remove all text lines beginning with the line that starts with "xxx" and the line that ends with "xxx", inclusive.
I know how to do this in Java or C++, but can someone show me a simple script that can get this done?
Thanks!... | [
"I assume that you want to lose start and end, and those words appear by themselves on the lines you want lost.\nperl -ni.bak -e 'print unless /^start$/../^end$/' *.txt\n\nNote that I made a backup of the modified files so that you can inspect the change and fix it if you want.\n",
"Not that there’s anything wron... | [
8,
2,
0
] | [] | [] | [
"perl",
"python",
"regex"
] | stackoverflow_0005752286_perl_python_regex.txt |
Q:
How can I use readline() to begin from the second line?
I'm writing a short program in Python that will read a FASTA file which is usually in this format:
>gi|253795547|ref|NC_012960.1| Candidatus Hodgkinia cicadicola Dsem chromosome, 52 lines
GACGGCTTGTTTGCGTGCGACGAGTTTAGGATTGCTCTTTTGCTAAGCTTGGGGGTTGCGCCCAAAGTGA
... | How can I use readline() to begin from the second line? | I'm writing a short program in Python that will read a FASTA file which is usually in this format:
>gi|253795547|ref|NC_012960.1| Candidatus Hodgkinia cicadicola Dsem chromosome, 52 lines
GACGGCTTGTTTGCGTGCGACGAGTTTAGGATTGCTCTTTTGCTAAGCTTGGGGGTTGCGCCCAAAGTGA
TTAGATTTTCCGACAGCGTACGGCGCGCGCTGCTGAACGTGGCCACTGAGCTTACACCTCA... | [
"def readSeq(FASTA):\n \"\"\"returns the DNA sequence of a FASTA file\"\"\"\n _unused = FASTA.next() # skip heading record\n for line in FASTA:\n line = line.strip()\n print line \n\nRead the docs on file.next() to see why you should be wary of mixing file.readline() with for line in file: \... | [
5,
4,
2,
1,
1
] | [] | [] | [
"python"
] | stackoverflow_0005752595_python.txt |
Q:
Can't read stderr from subprocess.Popen
I want to start a child process and read its stderr, but so far, I can't read anything at all using subprocess.Popen, even stdout. I'm trying to use subprocess.communicate() to read from stdout and stderr. This is what I do:
import subprocess
p = subprocess.Popen('ls')
s = p... | Can't read stderr from subprocess.Popen | I want to start a child process and read its stderr, but so far, I can't read anything at all using subprocess.Popen, even stdout. I'm trying to use subprocess.communicate() to read from stdout and stderr. This is what I do:
import subprocess
p = subprocess.Popen('ls')
s = p.communicate()
print s
This gives me output ... | [
"You need to specify the stdout=subprocess.PIPE and stderr=subprocess.PIPE when you create your Popen object:\n p = subprocess.Popen('ls', stdout=subprocess.PIPE, stderr=subprocess.PIPE)\n\n",
"From Python docs (Subprocess module):\nPopen.communicate(input=None) \n\nInteract with process: Send data to stdin. Rea... | [
4,
1
] | [] | [] | [
"python",
"subprocess"
] | stackoverflow_0005752702_python_subprocess.txt |
Q:
Is it Pythonic to use list comprehensions for just side effects?
Think about a function that I'm calling for its side effects, not return values (like printing to screen, updating GUI, printing to a file, etc.).
def fun_with_side_effects(x):
...side effects...
return y
Now, is it Pythonic to use list comp... | Is it Pythonic to use list comprehensions for just side effects? | Think about a function that I'm calling for its side effects, not return values (like printing to screen, updating GUI, printing to a file, etc.).
def fun_with_side_effects(x):
...side effects...
return y
Now, is it Pythonic to use list comprehensions to call this func:
[fun_with_side_effects(x) for x in y if ... | [
"It is very anti-Pythonic to do so, and any seasoned Pythonista will give you hell over it. The intermediate list is thrown away after it is created, and it could potentially be very, very large, and therefore expensive to create.\n",
"You shouldn't use a list comprehension, because as people have said that will ... | [
107,
45,
28,
13,
4,
0,
0
] | [] | [] | [
"list_comprehension",
"python"
] | stackoverflow_0005753597_list_comprehension_python.txt |
Q:
Passing meta-characters to Python as arguments from command line
I'm making a Python program that will parse the fields in some input lines. I'd like to let the user enter the field separator as an option from the command line. I'm using optparse to do this. I'm running into the problem that entering something lik... | Passing meta-characters to Python as arguments from command line | I'm making a Python program that will parse the fields in some input lines. I'd like to let the user enter the field separator as an option from the command line. I'm using optparse to do this. I'm running into the problem that entering something like \t will separate literally on \t, rather than on a tab, which is wha... | [
">>> r'\\t\\n\\v\\r'.decode('string-escape')\n'\\t\\n\\x0b\\r'\n\n",
"The quick and dirty way is to to eval it, like this:\neval(options.delimiter, {}. {})\n\nThe extra empty dicts are there to prevent accidental clobbering of your program.\n",
"solving it from within your script:\noptions.delimiter = re.sub(\"... | [
7,
0,
0,
0
] | [] | [] | [
"backslash",
"command_line_arguments",
"escaping",
"python"
] | stackoverflow_0005753332_backslash_command_line_arguments_escaping_python.txt |
Q:
How can I resolve a "[Errno 13] file not accessible" error?
My web application uses Django (django-nonrel) on Google App Engine. I am trying to open a Blobstore file.
My code successfully creates the Blobstore file and a Photo object to refer to the Blobstore's file name (along with some other metadata).
from __f... | How can I resolve a "[Errno 13] file not accessible" error? | My web application uses Django (django-nonrel) on Google App Engine. I am trying to open a Blobstore file.
My code successfully creates the Blobstore file and a Photo object to refer to the Blobstore's file name (along with some other metadata).
from __future__ import with_statement
from google.appengine.api import fi... | [
"Blobstore files are stored in, well, the blobstore. open is a function that opens files on the local filesystem (modulo special cases like writing blobs). As per the docs, if you want to open the blobstore file after it's finalized, you need to call files.blobstore.get_blob_key(file_name) on the filename to get th... | [
4
] | [] | [] | [
"blobstore",
"django",
"google_app_engine",
"python"
] | stackoverflow_0005753527_blobstore_django_google_app_engine_python.txt |
Q:
SqlAlchemy IntegrityError
I'm trying to get a whole bunch of data off of facebook, and add objects into the database as I process them. For likes, for example, I am just making them the ID of the person who issued the like. However, when I add more than one like I will encounter an integrity error in sqlalchemy be... | SqlAlchemy IntegrityError | I'm trying to get a whole bunch of data off of facebook, and add objects into the database as I process them. For likes, for example, I am just making them the ID of the person who issued the like. However, when I add more than one like I will encounter an integrity error in sqlalchemy because the primary keys are not ... | [
"Do you realy need to optimize it for heavy load? Probably not, having you are using SQLite. The simple solution in this case is much better:\nclass Like(Base):\n __tablename__ = 'Like'\n id = Column(Integer, primary_key=True)\n counter = Column(Integer, nullable=False, default=0)\n\n\no = session.merge(Li... | [
6
] | [] | [] | [
"database",
"database_design",
"python",
"sqlalchemy",
"sqlite"
] | stackoverflow_0005750677_database_database_design_python_sqlalchemy_sqlite.txt |
Q:
Python float numbers representation
Possible Duplicate:
Floating Point Limitations
Hi there,
maybe this has a very simple answer. I was playing around with the Python interpreter.
>>> 1
1
>>> 1.1
1.1000000000000001
>>> 1.2
1.2
Why 1.1 was interpreted as 1.1000000000000001?
A:
From The Floating-Point Guide:
W... | Python float numbers representation |
Possible Duplicate:
Floating Point Limitations
Hi there,
maybe this has a very simple answer. I was playing around with the Python interpreter.
>>> 1
1
>>> 1.1
1.1000000000000001
>>> 1.2
1.2
Why 1.1 was interpreted as 1.1000000000000001?
| [
"From The Floating-Point Guide:\n\nWhy don’t my numbers, like 0.1 + 0.2 add up to a nice round 0.3, and\n instead I get a weird result like\n 0.30000000000000004?\nBecause internally, computers use a\n format (binary floating-point) that\n cannot accurately represent a number\n like 0.1, 0.2 or 0.3 at all.\nWh... | [
1,
0,
0
] | [] | [] | [
"floating_point",
"python"
] | stackoverflow_0005754284_floating_point_python.txt |
Q:
recommended structure for python desktop development
I am a happy django developer and now want to build a small python desktop app. I have decided to use wxpython as my gui toolkit.
Now starts the confusion. How should I organize my code? are there any simple starting point schemes? Any pointers to real world cod... | recommended structure for python desktop development | I am a happy django developer and now want to build a small python desktop app. I have decided to use wxpython as my gui toolkit.
Now starts the confusion. How should I organize my code? are there any simple starting point schemes? Any pointers to real world code of small wxpython application with database interactions... | [
"This is my favorite way to get started with a new wxPython project: http://www.oneminutepython.com/\nIt also starts laying out the code for you in a nice way.\n",
"I stick to the \"what I write, that I get\" rule. So I usually start with one of those:\n1) Using default Frame sizer for panel:\n\nimport wx\n\nclas... | [
3,
0
] | [] | [] | [
"python",
"user_interface",
"wxpython"
] | stackoverflow_0005747907_python_user_interface_wxpython.txt |
Q:
performing set operations on custom classes in python
I'd like to use Python's built-in set class with a custom class that I've created. If I want
to create sets containing instances of my custom class, what functions do I need to implement so that I can perform tests, like set_a - set_b?
A:
It will work out of... | performing set operations on custom classes in python | I'd like to use Python's built-in set class with a custom class that I've created. If I want
to create sets containing instances of my custom class, what functions do I need to implement so that I can perform tests, like set_a - set_b?
| [
"It will work out of the box, however, there might be cases, when it makes sense to overload __eq__, __ne__ and __hash__. By default, __eq__ will compare for object identity. This might not be what you want. In that case, you have to take care that equal object have equal hashes, and, ideally, not equal object have... | [
52
] | [] | [] | [
"python",
"set"
] | stackoverflow_0005754440_python_set.txt |
Q:
Mix Python Twisted with multiprocessing?
I need to write a proxy like program in Python, the work flow is very similar to a web proxy. The program sits in between the client and the server, incept requests sent by the client to the server, process the request, then send it to the original server. Of course the pro... | Mix Python Twisted with multiprocessing? | I need to write a proxy like program in Python, the work flow is very similar to a web proxy. The program sits in between the client and the server, incept requests sent by the client to the server, process the request, then send it to the original server. Of course the protocol used is a private protocol uses TCP.
To ... | [
"Twisted has its own event-driven way of running subprocesses which is (in my humble, but correct, opinion) better than the multiprocessing module. The core API is spawnProcess, but tools like ampoule provide higher-level wrappers over it.\nIf you use spawnProcess, you will be able to handle output from subprocess... | [
18,
4,
0
] | [] | [] | [
"multiprocessing",
"python",
"twisted"
] | stackoverflow_0005715217_multiprocessing_python_twisted.txt |
Q:
Resize animated GIF with PythonMagick
I'm using PythonMagick 0.9.3 (cannot switch to PIL) to resize images. It works fine for everything except for animated GIFs.
This is the way how I resize the images at the moment:
orig_image = Image('path/to/animated.gif')
orig_image.resize('..resize string..')
orig_image.wri... | Resize animated GIF with PythonMagick | I'm using PythonMagick 0.9.3 (cannot switch to PIL) to resize images. It works fine for everything except for animated GIFs.
This is the way how I resize the images at the moment:
orig_image = Image('path/to/animated.gif')
orig_image.resize('..resize string..')
orig_image.write('path/to/thumbnail.gif')
Currently it o... | [
"I suppose you have to iterate on all the images that compose the animation, resize them, and recompose the animation after like this (with example for PHP language)\n"
] | [
0
] | [] | [] | [
"animated_gif",
"imagemagick",
"python",
"thumbnails"
] | stackoverflow_0005728911_animated_gif_imagemagick_python_thumbnails.txt |
Q:
html code generated by django template
Sorry if this is a completely retarded question, but I was wondering if it's possible to see the pure html code generated by a django template. Again, I'm really new to django, so I apologize if this is a stupid question.
Thanks!
A:
Django templates don't result in HTML c... | html code generated by django template | Sorry if this is a completely retarded question, but I was wondering if it's possible to see the pure html code generated by a django template. Again, I'm really new to django, so I apologize if this is a stupid question.
Thanks!
| [
"Django templates don't result in HTML code, they result in a node tree. The engine then renders the node tree in order to generate the appropriate output.\n",
"It might seem like a slightly obvious answer, but have you tried \"View Source\" in your browser? \nIf you want to improve your understanding, read the D... | [
6,
2
] | [] | [] | [
"django",
"python"
] | stackoverflow_0005753586_django_python.txt |
Q:
Why does this python regular expression return the wrong string
Below I have a piece of code that should replace one string with another but doesnt seem to do it. I am not a python or regular expression expert, can anyone tell me why this might be going wrong.
def ReplaceCRC( file_path ):
file = open(file_pat... | Why does this python regular expression return the wrong string | Below I have a piece of code that should replace one string with another but doesnt seem to do it. I am not a python or regular expression expert, can anyone tell me why this might be going wrong.
def ReplaceCRC( file_path ):
file = open(file_path,'r+');
file_str = file.read()
if( file_str <> '' ):
... | [
"Not your problem, but these 3 lines are amazing:\nfinal = hex(CalcCRC( str_to_crc ))[:2]\nvalue = '%08X' % CalcCRC( str_to_crc )\nfinal = final + value.upper()\n\nAssuming CalcCRC returns a non-negative integer (e.g. 12345567890\nLine 1 sets final to \"0x\" irrespective of the input!\... | [
1,
0,
0
] | [] | [] | [
"crc32",
"python",
"regex"
] | stackoverflow_0005753457_crc32_python_regex.txt |
Q:
Which encoding?
does anybody know in which way the string 'Krummh%C3%B6rn' is encoded?
Plain text is "Krummhörn".
I need to decode strings like this one in Python and tried urllib.unquote('Krummh%C3%B6rn')
The result: 'Krummh\xc3\xb6rn'
A:
That's UTF-8 in URL encoding.
print(urllib.unquote('Krummh%C3%B6rn').deco... | Which encoding? | does anybody know in which way the string 'Krummh%C3%B6rn' is encoded?
Plain text is "Krummhörn".
I need to decode strings like this one in Python and tried urllib.unquote('Krummh%C3%B6rn')
The result: 'Krummh\xc3\xb6rn'
| [
"That's UTF-8 in URL encoding.\nprint(urllib.unquote('Krummh%C3%B6rn').decode('utf-8'))\n\nprints the string as you'd expect it to look.\n",
"You're halfway there. Take that result and decode it as UTF-8.\n",
"Looks like URL encoding\n"
] | [
5,
4,
0
] | [] | [] | [
"encoding",
"python",
"urldecode"
] | stackoverflow_0005755058_encoding_python_urldecode.txt |
Q:
Similar Functions - One works, the rest don't - Maybe a fresh set of eyes can see the problem? (Python CGI)
Working on a low intensity user registration script. In the error checking portion of the script (which effectively just checks to make sure the fields aren't left blank), the "addressError" function works w... | Similar Functions - One works, the rest don't - Maybe a fresh set of eyes can see the problem? (Python CGI) | Working on a low intensity user registration script. In the error checking portion of the script (which effectively just checks to make sure the fields aren't left blank), the "addressError" function works without any problems at all.
But if I try to create errors in any other field, the script times out. Hopefully so... | [
"Python has mechanisms for creating functions dynamically that are useful in situations like this. One is the metaclass, which requires some double-indirect thinking and can be tortuous to think thru. A simpler one (and a stepping stone to eventually learning metaclasses) is the closure, a function that creates a ... | [
1,
0
] | [] | [] | [
"cgi",
"python",
"webforms"
] | stackoverflow_0005754600_cgi_python_webforms.txt |
Q:
Twitter Streaming API Python library with proxy support?
I am looking for a Twitter Streaming API Python library with proxy support. I love tweepy, but unfortunately I haven't seen a way to use an HTTP proxy. Any ideas?
A:
Check this tweepy commit; it uses urllib2 for executing APIMethods through proxies.
A:
T... | Twitter Streaming API Python library with proxy support? | I am looking for a Twitter Streaming API Python library with proxy support. I love tweepy, but unfortunately I haven't seen a way to use an HTTP proxy. Any ideas?
| [
"Check this tweepy commit; it uses urllib2 for executing APIMethods through proxies.\n",
"Tweepy uses httplib internally which is too low level to have proxy settings. You have to change Stream._run() method to connect to proxy instead of target host and use full (with scheme and host) URL in request.\n"
] | [
4,
2
] | [] | [] | [
"api",
"proxy",
"python",
"streaming",
"twitter"
] | stackoverflow_0005700302_api_proxy_python_streaming_twitter.txt |
Q:
Using assert within methods - Python
is it bad practice to use asserts within methods?
e.g.
def add(x, y):
assert isinstance(x, int) and isinstance(y, int)
return x + y
Any ideas?
A:
Not at all.
In your sample, provided you have documented that add expects integers, asserting this constraint at the begi... | Using assert within methods - Python | is it bad practice to use asserts within methods?
e.g.
def add(x, y):
assert isinstance(x, int) and isinstance(y, int)
return x + y
Any ideas?
| [
"Not at all.\nIn your sample, provided you have documented that add expects integers, asserting this constraint at the beginning of the method is actually great practice.\nJust imagine the other choices you have and how bad they are:\n\ndon't verify your arguments. This means, the method will fail later with a stra... | [
7,
2,
0,
0
] | [] | [] | [
"assert",
"exception_handling",
"python"
] | stackoverflow_0005755485_assert_exception_handling_python.txt |
Q:
superimpose an image over another image with python
Is there a built in function that allows an image to be added over another image in python? Thanks a lot
A:
Use the blend function from the Image module: http://effbot.org/imagingbook/image.htm
A:
Image.paste() from PIL will do that.
| superimpose an image over another image with python | Is there a built in function that allows an image to be added over another image in python? Thanks a lot
| [
"Use the blend function from the Image module: http://effbot.org/imagingbook/image.htm\n",
"Image.paste() from PIL will do that.\n"
] | [
6,
3
] | [] | [] | [
"image",
"python"
] | stackoverflow_0005755867_image_python.txt |
Q:
Does Python have an equivalent to java.lang.Math.nextUp?
I have a Python float, and I want to have the floats which are 1 ULP greater and lesser.
In Java, I would do this with Math.nextUp(x) and Math.nextAfter(x, Double.NEGATIVE_INFINITY).
Is there a way to do this in Python? I thought about implementing it mysel... | Does Python have an equivalent to java.lang.Math.nextUp? | I have a Python float, and I want to have the floats which are 1 ULP greater and lesser.
In Java, I would do this with Math.nextUp(x) and Math.nextAfter(x, Double.NEGATIVE_INFINITY).
Is there a way to do this in Python? I thought about implementing it myself with math.frexp and math.ldexp but as far as I know Python d... | [
"Update: In Python 3.9+ there is math.nextafter():\n>>> import math\n>>> x = 4\n>>> math.nextafter(x, math.inf)\n4.000000000000001\n\n\nOld answer:\nYou could look at how Decimal.next_plus()/Decimal.next_minus() are implemented:\n>>> from decimal import Decimal as D\n>>> d = D.from_float(123456.78901234567890)\n>>>... | [
4,
1
] | [] | [] | [
"floating_point",
"python"
] | stackoverflow_0005749188_floating_point_python.txt |
Q:
Mysqldb AttributeError: cursor
I am starting to use the mysqldb module in python and I seem to have some issues with the "standard" way of calling queries.
I understand that the standard way is to create a cursor and then use it to execute queries.
However, when I try to instanciate one, it gives me the following ... | Mysqldb AttributeError: cursor | I am starting to use the mysqldb module in python and I seem to have some issues with the "standard" way of calling queries.
I understand that the standard way is to create a cursor and then use it to execute queries.
However, when I try to instanciate one, it gives me the following error :
AttributeError: cursor
My ... | [
"You are using wrong connection constructor.\nMySQLdb.Connection instead of MySQLdb.connection should work.\n"
] | [
6
] | [] | [] | [
"mysql",
"mysql_python",
"python"
] | stackoverflow_0005755837_mysql_mysql_python_python.txt |
Q:
run python command line arguments in shell script
I have a script which takes in few arguments
./hal --runtest=example
where example = /home/user/example.py
how can I pass these arguments in shell script?
A:
I'm having trouble figuring out what you're asking, but assuming your question is "How can a shell scrip... | run python command line arguments in shell script | I have a script which takes in few arguments
./hal --runtest=example
where example = /home/user/example.py
how can I pass these arguments in shell script?
| [
"I'm having trouble figuring out what you're asking, but assuming your question is \"How can a shell script pass dynamic arguments to a command that happens to be written in Python\" and you are using a Bourne-family shell (very likely), the simplest correct answer would be\nexample=/home/user/example.py\n./hal \"-... | [
1,
0,
0
] | [] | [] | [
"python",
"shell"
] | stackoverflow_0003603517_python_shell.txt |
Q:
Python PyQt4 progressbar Freezing GUI
the following code counts a bunch of PyQt4 progressbar's up tp 99%, I would like for my GUI NOT to freeze as they count up to 99%. I would LOVE to do this without custom classes or functions if it is possible.
I know it is good to use classes but for this tiny snippet of code ... | Python PyQt4 progressbar Freezing GUI | the following code counts a bunch of PyQt4 progressbar's up tp 99%, I would like for my GUI NOT to freeze as they count up to 99%. I would LOVE to do this without custom classes or functions if it is possible.
I know it is good to use classes but for this tiny snippet of code I don't want to create a class.
From what I... | [
"try changing your for loop with:\nwhile True:\n for a in range(10000):\n time.sleep(0.0001)\n for i in range(cntControl):\n barra[i].setValue(a)\n\nif works for me.\nThe while loop continues endlessly moving the bar. If you are looking only to clean the bar after it reaches the end you ... | [
1,
0
] | [] | [] | [
"freeze",
"progress_bar",
"pyqt4",
"python"
] | stackoverflow_0005743008_freeze_progress_bar_pyqt4_python.txt |
Q:
Are there advantages to use the Python/C interface instead of Cython?
I want to extend python and numpy by writing some modules in C or C++, using BLAS and LAPACK. I also want to be able to distribute the code as standalone C/C++ libraries. I would like this libraries to use both single and double precision float.... | Are there advantages to use the Python/C interface instead of Cython? | I want to extend python and numpy by writing some modules in C or C++, using BLAS and LAPACK. I also want to be able to distribute the code as standalone C/C++ libraries. I would like this libraries to use both single and double precision float. Some examples of functions I will write are conjugate gradient for solving... | [
"The current \"top answer\" sounds a bit too much like FUD in my ears. For one, it is not immediately obvious that the Average Developer would write faster code in C than what NumPy+Cython gives you anyway. Quite the contrary, the time it takes to even get the necessary C code to work correctly in a Python environm... | [
92,
11,
0
] | [] | [] | [
"c",
"cython",
"numpy",
"python"
] | stackoverflow_0005720272_c_cython_numpy_python.txt |
Q:
Adding elements to a tuple when I know I shouldn't be able to
Dive Into Python is one of many sources that says:
You can't add elements to a tuple.
But it looks as if I was allowed to do just that. My code:
from string import find
def subStringMatchExact(target, key):
t = (99,)
location = find(target, k... | Adding elements to a tuple when I know I shouldn't be able to | Dive Into Python is one of many sources that says:
You can't add elements to a tuple.
But it looks as if I was allowed to do just that. My code:
from string import find
def subStringMatchExact(target, key):
t = (99,)
location = find(target, key)
while location != -1
t += (location,) # Why is t... | [
"You are concatenating 2 tuples in a new one.\nYou are not modifying the original.\n> a = (1,)\n> b = a\n> b == a\nTrue\n> a += (2,)\n> b == a\nFalse\n\n",
"t += (location,) is a shorthand for t = t + (location,) so you are creating a new tuple instance and assigning that to t each time around the loop.\n",
"My... | [
12,
3,
2
] | [] | [] | [
"python",
"tuples"
] | stackoverflow_0005756768_python_tuples.txt |
Q:
Error running app on Google App Engine
I get this strange message error when trying to run an app using dev_appserver.py:
ERROR 2011-04-21 23:03:44,984 dev_appserver_main.py:407] Fatal error when loading
application configuration:
Value 'warmup' for key ??? does not match expression '^(mail|xmpp_message|rest|st... | Error running app on Google App Engine | I get this strange message error when trying to run an app using dev_appserver.py:
ERROR 2011-04-21 23:03:44,984 dev_appserver_main.py:407] Fatal error when loading
application configuration:
Value 'warmup' for key ??? does not match expression '^(mail|xmpp_message|rest|startup)$'
in "stackprinter/app.yaml", line 53... | [
"Solved!\nThe problem was that i had an old GAE SDK, Warmup requests were added in the 1.4.0 version. \nCheers\n"
] | [
1
] | [] | [] | [
"google_app_engine",
"python"
] | stackoverflow_0005750730_google_app_engine_python.txt |
Q:
List available languages for PyGTK UI strings
I'm cleaning up some localisation and translation settings in our PyGTK application. The app is only intended to be used under GNU/Linux systems. One of the features we want is for users to select the language used for the applications (some prefer their native languag... | List available languages for PyGTK UI strings | I'm cleaning up some localisation and translation settings in our PyGTK application. The app is only intended to be used under GNU/Linux systems. One of the features we want is for users to select the language used for the applications (some prefer their native language, some prefer English for consistency, some like F... | [
"You can use gettext to find whether a translation is available and installed, but you need babel (which was available on my Ubuntu system as the package python-pybabel) to get the names. Here is a code snippet which returns the list that you want:\nimport gettext\nimport babel\n\nmessagefiles = gettext.find('OurAp... | [
2,
1
] | [] | [] | [
"gettext",
"gtk",
"pygtk",
"python",
"translation"
] | stackoverflow_0002891254_gettext_gtk_pygtk_python_translation.txt |
Q:
Python NameError when var IS most definitely defined
def make_pdf(self):
self.get_filez()
self.get_client()
file_name = self.client_id+"_"+self.client_name+"_"+self.batch_num
style = libxslt.parseStylesheetDoc(self.xsl_file)
transformation = style.applyStylesheet(self.xml... | Python NameError when var IS most definitely defined | def make_pdf(self):
self.get_filez()
self.get_client()
file_name = self.client_id+"_"+self.client_name+"_"+self.batch_num
style = libxslt.parseStylesheetDoc(self.xsl_file)
transformation = style.applyStylesheet(self.xml_file,None)
style.saveResultToFilename("tmp/"+file... | [
"Mysterious NameErrors may arise from your file containing invisible control characters. On unix machines, you can spot these errors by looking at the output of\ncat -A filename.py\n\n",
"Try to print file_name after each line, to see if somebody is removing the \"file_name\" variable from your namespace.\nIn add... | [
2,
1,
0
] | [] | [] | [
"python"
] | stackoverflow_0005756777_python.txt |
Q:
Simple but fast IPC method for a Python and C++ application?
I have a GNU Radio application which utilizes both Python and C++ code. I want to be able to signal the C++ code of an event. If they were in the same scope I would normally use a simple boolean, but the code is separate to the point where some form of s... | Simple but fast IPC method for a Python and C++ application? | I have a GNU Radio application which utilizes both Python and C++ code. I want to be able to signal the C++ code of an event. If they were in the same scope I would normally use a simple boolean, but the code is separate to the point where some form of shared memory is required. The code in question is performance-crit... | [
"Assuming this is two separate applications on one machine and you need decent real time performance you don't want to go with sockets. I would use a flag in shared memory, and probably use a semaphore to make sure both programs can't be accessing the flag at once. This library provides access to the semaphores and... | [
12,
5,
3,
1,
1
] | [] | [] | [
"c++",
"ipc",
"linux",
"python"
] | stackoverflow_0005756813_c++_ipc_linux_python.txt |
Q:
Problem looping through files in directory while checking database with Python
I'm trying to process a bunch of csv files in a given directory. Each time I run the script, it goes through each file in the directory (in case I've added new ones), and then checks agains the database to see if the file has been proc... | Problem looping through files in directory while checking database with Python | I'm trying to process a bunch of csv files in a given directory. Each time I run the script, it goes through each file in the directory (in case I've added new ones), and then checks agains the database to see if the file has been processed, and if so, what line to start processing from.
Problem is, the script seems t... | [
"Based on your comments, oughtn't there be a break statement in the else clause after file_to_be_processed = filename too?\nAlso note that this variable is misnamed file_to_processed a few lines above.\nAlso note that status[7] will probably throw an exception, since there only appear to be 7 fields in your table. ... | [
2
] | [] | [] | [
"file",
"mysql",
"python"
] | stackoverflow_0005756986_file_mysql_python.txt |
Q:
Basic inserting of image? Python
I use python on Ubuntu, and I am (as my name suggests) a complete noob at it all. I want to insert a very basic image, I have looked around, copied coding etc, but mothing seems to work. I want to insert an image, nothing else, so it just appears on the screen when I run it in shel... | Basic inserting of image? Python | I use python on Ubuntu, and I am (as my name suggests) a complete noob at it all. I want to insert a very basic image, I have looked around, copied coding etc, but mothing seems to work. I want to insert an image, nothing else, so it just appears on the screen when I run it in shell. Please help? and please explain in ... | [
"you can install PIL imagemagick\nthen:\nimport Image\n\nim = Image.open(\"your_image\")\nim.show()\n\n",
"I would try something like:\nimport webbrowser\nwebbrowser.open('file:///path/to/my/file.jpg')\n\n"
] | [
2,
1
] | [] | [] | [
"image",
"python"
] | stackoverflow_0005757220_image_python.txt |
Q:
condition of tuple of integers
how do I write a concise/neat boolean condition to test if all the integers in a tuple are in a given range? Something like
0 < (1,2,3) < 50
would be perfect - of course that doesn't work because it uses lexicographical ordering, so also
0 < (1,2,-3) < 50
evaluates to True. Inste... | condition of tuple of integers | how do I write a concise/neat boolean condition to test if all the integers in a tuple are in a given range? Something like
0 < (1,2,3) < 50
would be perfect - of course that doesn't work because it uses lexicographical ordering, so also
0 < (1,2,-3) < 50
evaluates to True. Instead I would want it to evaluate to Tr... | [
"all(0 < n < 50 for n in thetuple)\n\nshould be a relatively concise solution. it may not be the shortest piece of code, but it is almost self-documenting.\n"
] | [
15
] | [] | [] | [
"conditional_statements",
"python",
"tuples"
] | stackoverflow_0005757491_conditional_statements_python_tuples.txt |
Q:
ImportError on subpackage when running setup.py test
I'm trying to create an install package for a Python project with included unit tests. My project layout is as follows:
setup.py
src/
disttest/
__init__.py
core.py
tests/
disttest/
__init__.py
testcore.py
My setup.py look... | ImportError on subpackage when running setup.py test | I'm trying to create an install package for a Python project with included unit tests. My project layout is as follows:
setup.py
src/
disttest/
__init__.py
core.py
tests/
disttest/
__init__.py
testcore.py
My setup.py looks like this:
from distutils.core import setup
import setup... | [
"You may want to double-check this, but it looks like your tests are importing the disttest package in the tests/ directory, instead of the package-under-test from the src/ directory. \nWhy do you need to use a package with the same name as the package-under-test? I'd simply move the testcore module up to the tests... | [
2
] | [] | [] | [
"distutils",
"python",
"setuptools"
] | stackoverflow_0005662052_distutils_python_setuptools.txt |
Q:
Django: comparison on extra fields
Short question: Is there a way in Django to find the next row, based on the alphabetical order of some field, in a case-insensitive way?
Long question: I have some words in the database, and a detail view for them. I would like to be able to browse the words in alphabetical order... | Django: comparison on extra fields | Short question: Is there a way in Django to find the next row, based on the alphabetical order of some field, in a case-insensitive way?
Long question: I have some words in the database, and a detail view for them. I would like to be able to browse the words in alphabetical order. So I need to find out the id of the pr... | [
"The database should be able to do this sorting for you, and it should be able to do so without the \"lower\" function.\nReally what you need to fix is the database collation and encoding.\nFor example, if you are using mysql you could use the character set utf8 and collation utf8_general_ci\nIf that collation does... | [
1
] | [] | [] | [
"django",
"django_orm",
"python"
] | stackoverflow_0005756158_django_django_orm_python.txt |
Q:
Meaning of digits after NaN in Python Decimal object
I was reading the lexical definition for valid decimal string syntax in the documentation for decimal.Decimal and the following struck me as kind of odd:
nan ::= 'NaN' [digits] | 'sNaN' [digits]
This looked really strange to me, but apparently digit... | Meaning of digits after NaN in Python Decimal object | I was reading the lexical definition for valid decimal string syntax in the documentation for decimal.Decimal and the following struck me as kind of odd:
nan ::= 'NaN' [digits] | 'sNaN' [digits]
This looked really strange to me, but apparently digits can be included after 'NaN' without any issues, but any ... | [
"It is an IEEE-754 feature to distinguish between different kinds of NaNs (the \"payload\"). The digits are encoded into the mantissa of the number:\n>>> Decimal(\"NaN456\").as_tuple()\nDecimalTuple(sign=0, digits=(4, 5, 6), exponent='n')\n>>> Decimal(\"NaN123\").as_tuple()\nDecimalTuple(sign=0, digits=(1, 2, 3), e... | [
6
] | [] | [] | [
"python"
] | stackoverflow_0005757745_python.txt |
Q:
Reducing menu.add_command() clutter/repeat lines
I would like to do the following (just an example, the real code has more menu's and more add_command's):
editmenu.add_command(label="Cut",state="disabled")
editmenu.add_command(label="Copy",state="disabled")
editmenu.add_command(label="Paste",state="disabled")
edit... | Reducing menu.add_command() clutter/repeat lines | I would like to do the following (just an example, the real code has more menu's and more add_command's):
editmenu.add_command(label="Cut",state="disabled")
editmenu.add_command(label="Copy",state="disabled")
editmenu.add_command(label="Paste",state="disabled")
editmenu.add_command(label="Delete",state="disabled")
But... | [
"Here's a translation of what you wanted to do:\nfor labeldic in [{\"label\":\"Cut\"},{\"label\":\"Copy\"},{\"label\":\"Paste\"},{\"label\":\"Delete\"}]:\n labeldic.update({\"state\": \"disabled\"})\n editmenu.add_command(**labeldic)\n\nThere were three problems I fixed. \nThe first is that dictionary keys ne... | [
4
] | [] | [] | [
"python",
"syntax",
"tkinter",
"widget"
] | stackoverflow_0005757791_python_syntax_tkinter_widget.txt |
Q:
In For loop using two elements in python
In python list I have two items per element, 1st a str, second a float
L= [('A', Decimal('52.00')), ('B', Decimal('87.80')), ('G', Decimal('32.50'))]
I want use a for loop both item in the element
NewL= []
for row in L:
### do something with str
InSql= "SELECT " ... | In For loop using two elements in python | In python list I have two items per element, 1st a str, second a float
L= [('A', Decimal('52.00')), ('B', Decimal('87.80')), ('G', Decimal('32.50'))]
I want use a for loop both item in the element
NewL= []
for row in L:
### do something with str
InSql= "SELECT " % str
f= csr.execute(InSql)
ns = list(... | [
"Change your for loop to something like this:\nfor str_data, float_data in L:\n # str_data is the string, float_data is the Decimal object\n\n",
"Two ways:\nFirst you could access the members of row:\n#For string:\nrow[0]\n#For the number:\nrow[1]\n\nOr you specify your loop this way:\nfor (my_string, my_numbe... | [
5,
3,
3,
3
] | [] | [] | [
"for_loop",
"python"
] | stackoverflow_0005757922_for_loop_python.txt |
Q:
Python, __slots__, inheritance, and class variables ==> attribute is read-only bug
I have a big tree with hundreds of thousands of nodes, and I'm using __slots__ to reduce the memory consumption. I just found a very strange bug and fixed it, but I don't understand the behavior that I saw.
Here's a simplified code ... | Python, __slots__, inheritance, and class variables ==> attribute is read-only bug | I have a big tree with hundreds of thousands of nodes, and I'm using __slots__ to reduce the memory consumption. I just found a very strange bug and fixed it, but I don't understand the behavior that I saw.
Here's a simplified code sample:
class NodeBase(object):
__slots__ = ["name"]
def __init__(self, name):
... | [
"A smaller example:\nclass C(object):\n __slots__ = ('x',)\n x = 0\n\nC().x = 1\n\nThe documentation on slots states at one point:\n\n__slots__ are implemented at the class level by creating descriptors (Implementing Descriptors) for each variable name. As a result, class attributes cannot be used to set defa... | [
25
] | [] | [] | [
"python",
"slots"
] | stackoverflow_0005757924_python_slots.txt |
Q:
Python - sort list of list
I have a list in this format:
exon_start exon_finish gene_name (repeated hundreds of times)
I want to sort by exon_start
Example list:
['8342758', '8344137', 'NM_001042682']
['85420368', '85421471', 'NM_032184']
['86363115', '86364485', 'NM_152890']
['89820771', '89822936', 'NM_01535... | Python - sort list of list | I have a list in this format:
exon_start exon_finish gene_name (repeated hundreds of times)
I want to sort by exon_start
Example list:
['8342758', '8344137', 'NM_001042682']
['85420368', '85421471', 'NM_032184']
['86363115', '86364485', 'NM_152890']
['89820771', '89822936', 'NM_015350']
['904123', '905900', 'NR_02... | [
"It's sorting them as strings, so the order is 'alphabetically'. Which is to say, it's going character by character and comparing, instead of comparing them as scalar values.\nSo do:\nsorted_triplets = sorted(triplets, key=lambda x: int(x[0]))\n\nAnd it should work.\n",
"convert strings to numbers\nsorted(triplet... | [
4,
1,
0,
0,
0,
0
] | [] | [] | [
"list",
"python",
"sorting"
] | stackoverflow_0005758254_list_python_sorting.txt |
Q:
Recommended tools for web development with python under linux?
I'm planning to work on a project using Tornado / nginx / mySQL / jQuery and would be using linux (im new to linux too, i barely know what vim / emacs are). Which tools for web development with this stack would you recommend?
A:
I use gedit for most ... | Recommended tools for web development with python under linux? | I'm planning to work on a project using Tornado / nginx / mySQL / jQuery and would be using linux (im new to linux too, i barely know what vim / emacs are). Which tools for web development with this stack would you recommend?
| [
"I use gedit for most of my web programming. I know, it's not very hardcore, but it has syntax highlighting and some nice plugins and it's very user-friendly.\nI would recommend learning to use bash, ssh, and the mysql console especially. It beats any sort of database gui, hands down.\nBesides that and a web browse... | [
2,
1,
0,
0,
0
] | [] | [] | [
"linux",
"python"
] | stackoverflow_0005758354_linux_python.txt |
Q:
How to render non-anti-aliased font to internal image?
What is the most speedy way and accurate to render non-anti-aliased fonts (e.g. ttf fonts) using Python to an internal image (e.g. to a PIL.Image, i.e. I don't need to display it)? I say accurate because I tried it with pygame a while back and the rendered fon... | How to render non-anti-aliased font to internal image? | What is the most speedy way and accurate to render non-anti-aliased fonts (e.g. ttf fonts) using Python to an internal image (e.g. to a PIL.Image, i.e. I don't need to display it)? I say accurate because I tried it with pygame a while back and the rendered fonts at the size I gave it didn't match what windows rendered ... | [
"Python Imaging Library (PIL) can render text to an image--I'm not aware of it being inaccurate, but I haven't fully tested it yet...\nExample from a pre-existing question:\nfrom PIL import Image\nfrom PIL import ImageFont, ImageDraw\n\nimage = Image.new(\"RGBA\", (288,432), (255,255,255))\nusr_font = ImageFont.tru... | [
8,
1
] | [] | [] | [
"fonts",
"image",
"python",
"render",
"truetype"
] | stackoverflow_0005747739_fonts_image_python_render_truetype.txt |
Q:
Get the difference between dates in the form of list years and months
Sorry for my english.
I have a two dates(DateTime):
latest_client = Client.objects.all().latest('id').ordered_at
first_client = Client.objects.order_by()[0].ordered_at
2011-04-22 15:27:28 - latest_client
2010-03-17 21:00:0 - first_client
I nee... | Get the difference between dates in the form of list years and months | Sorry for my english.
I have a two dates(DateTime):
latest_client = Client.objects.all().latest('id').ordered_at
first_client = Client.objects.order_by()[0].ordered_at
2011-04-22 15:27:28 - latest_client
2010-03-17 21:00:0 - first_client
I need to get the difference between dates in the form of list years and months:... | [
"Here is a generator that gives you datetime.date() spanning the months between start and end (inclusive)\nfrom datetime import date, datetime\ndef spanning_months(start, end):\n assert start <= end\n current = start.year * 12 + start.month - 1\n end = end.year * 12 + end.month - 1\n while current <= en... | [
4
] | [] | [] | [
"date",
"datetime",
"python"
] | stackoverflow_0005758262_date_datetime_python.txt |
Q:
Capture google app engine logging output
How can one view the Google App Engine logs outside the Admin console?
I'm developing, so using dev_appserver.py/the Admin Console and would like to see the logs as the records are emitted.
I'd like to monitor the logging output in a console with standard Unix tools e.g. le... | Capture google app engine logging output | How can one view the Google App Engine logs outside the Admin console?
I'm developing, so using dev_appserver.py/the Admin Console and would like to see the logs as the records are emitted.
I'd like to monitor the logging output in a console with standard Unix tools e.g. less/grep/etc, but there doesn't seem to be an o... | [
"The default logger sends logging output to stderr. Use your shell's method of redirecting stderr to a file (in tcsh, (dev_appserver.py > /dev/tty) >& your_logfile.txt, your shell may vary.)\nYou can also use the logging module in python to change the logger to send directly to a file if you detect it's running loc... | [
5,
2
] | [] | [] | [
"google_app_engine",
"logging",
"python"
] | stackoverflow_0005757945_google_app_engine_logging_python.txt |
Q:
Sphinx PDF output: Apostrophes in python source are replaced by right single quotes
I am outputting some documentation as PDF using Sphinx. It's all very fine except for when python source code are output, then single quotes (unicode U+0027) are output as right single quotes (U+2019) which look awkward.
Here are i... | Sphinx PDF output: Apostrophes in python source are replaced by right single quotes | I am outputting some documentation as PDF using Sphinx. It's all very fine except for when python source code are output, then single quotes (unicode U+0027) are output as right single quotes (U+2019) which look awkward.
Here are images of the glyphs in question and here is my generated PDF.
Does anybody know how to co... | [
"Add this to your sphinx conf.py (or append to latex_preamble if it is already set):\nlatex_preamble = \"\"\"\n\\usepackage{upquote}\n\"\"\"\n\n"
] | [
4
] | [] | [] | [
"latex",
"pdf",
"python",
"python_sphinx"
] | stackoverflow_0005757630_latex_pdf_python_python_sphinx.txt |
Q:
Python math domain error on distance formula
In my code:
class Vector(object):
@staticmethod
def distance(vector1, vector2):
return math.sqrt((vector2[0]-vector1[0])^2+(vector2[1]-vector1[1])^2)
Sometimes, seemingly at random, I get a ValueError: math domain error when calling this method. What's ... | Python math domain error on distance formula | In my code:
class Vector(object):
@staticmethod
def distance(vector1, vector2):
return math.sqrt((vector2[0]-vector1[0])^2+(vector2[1]-vector1[1])^2)
Sometimes, seemingly at random, I get a ValueError: math domain error when calling this method. What's the issue? Thanks.
| [
"Use ** to raise to a power, i.e. \n return math.sqrt((vector2[0]-vector1[0])**2+(vector2[1]-vector1[1])**2)\n\nIn Python and many other C-derived languages, ^ stands for bitwise-xor, and it could create a negative number, leading to that \"math domain error\".\nBTW, the whole operation can be computed with the ... | [
15,
2
] | [] | [] | [
"math",
"python"
] | stackoverflow_0005759034_math_python.txt |
Q:
Python 3.0 - I am having a problem getting the blank lines to go away in tkinter when a correct letter is entered
I am having a problem getting the blank lines to go away in tkinter when a correct letter is entered.
from tkinter import*
from random import*
from functools import*
wordList = [ 'apple', 'orange', 'f... | Python 3.0 - I am having a problem getting the blank lines to go away in tkinter when a correct letter is entered | I am having a problem getting the blank lines to go away in tkinter when a correct letter is entered.
from tkinter import*
from random import*
from functools import*
wordList = [ 'apple', 'orange', 'fancy', 'book', 'happy', 'games', 'mouse', 'water', 'worms', 'shoes', 'hands', 'gateway', 'keyboard', 'marker', 'collaps... | [
"If I read your question correctly, you want ____ to disappear and be replaced with the correct letter surrounded by whitespace?\nIn underscore() you append the underline characters every time through the loop. Instead, if the letter is correct, just print the letter and some spaces on either side:\ndef underscore(... | [
0
] | [] | [] | [
"python"
] | stackoverflow_0005758904_python.txt |
Q:
Regular Expression for checking a tag and getting a specific portion of the strings
I am facing a problem with regular expression. I am checking strings like tag:
<a href="/abc/def/ghk/">test_test</a>. I want to capture only the /abc/def/ghk portion using a regular expression.
I am using python and have tried with... | Regular Expression for checking a tag and getting a specific portion of the strings | I am facing a problem with regular expression. I am checking strings like tag:
<a href="/abc/def/ghk/">test_test</a>. I want to capture only the /abc/def/ghk portion using a regular expression.
I am using python and have tried with different expressions.
| [
"I'd use BeautifulSoup, as it's made for doing things like this:\n>>> from BeautifulSoup import BeautifulSoup\n>>> soup = BeautifulSoup('<a href=\"/abc/def/ghk/\">test_test</a>')\n>>> print soup.findAll('a', {'href': True})[0]['href']\n/abc/def/ghk/\n\n",
"Is this sufficient?\n>>> re.search('<a\\s+href=\"(\\S+?)\... | [
4,
1,
1
] | [] | [] | [
"python",
"regex"
] | stackoverflow_0005757627_python_regex.txt |
Q:
How to call a dll function in parallel in Python
I have a python program that uses ctypes to call a dll function to which I pass a pointer. It is supposed to write data continuously to that pointer and I want my program to loop and read the pointers contents. A rough template would look like:
from ctypes import *
... | How to call a dll function in parallel in Python | I have a python program that uses ctypes to call a dll function to which I pass a pointer. It is supposed to write data continuously to that pointer and I want my program to loop and read the pointers contents. A rough template would look like:
from ctypes import *
import copy
lib = cdll.lib
pointer = c_char_p(" "*100)... | [
"This can definitely work using threading, since ctypes releases the GIL before calling a C function. This enables (among other things) the C routine to call back into Python code without creating a deadlock. \nAbout the only problem you'll encounter is how to signal to the DLL to stop delivering data, but there a... | [
9,
0
] | [] | [] | [
"multithreading",
"python"
] | stackoverflow_0005759377_multithreading_python.txt |
Q:
django - python
I am very new to django, python and ubuntu command line. I've been installing an application on PC's and this is my third one. Ive come across this error and am not sure where else to look. When I run
python manage.py syncdb
i receive the following error
django.core.exceptions.ImproperlyConfigured:... | django - python | I am very new to django, python and ubuntu command line. I've been installing an application on PC's and this is my third one. Ive come across this error and am not sure where else to look. When I run
python manage.py syncdb
i receive the following error
django.core.exceptions.ImproperlyConfigured: Cannot determine Pos... | [
"Check Your PostGIS Version. it must be atleast 1.3.\n",
"Have you gone through this character-building documentation:\nhttp://docs.djangoproject.com/en/dev/ref/contrib/gis/install/\n?\nWe need to know more about versions of things and what steps you took to come to this error. Otherwise, the error is pretty inf... | [
1,
1,
0
] | [] | [] | [
"django",
"geodjango",
"postgis",
"python"
] | stackoverflow_0005759826_django_geodjango_postgis_python.txt |
Q:
Consolidating two text files with Python
Im trying to iterate through two different text files and create one consolidated file based on the account number found at the beginning of each line in both files. I begin by reading the main file which contains statement data and read each line until I find an account n... | Consolidating two text files with Python | Im trying to iterate through two different text files and create one consolidated file based on the account number found at the beginning of each line in both files. I begin by reading the main file which contains statement data and read each line until I find an account number that doesn't match the previous line, I ... | [
"Use dictionaries for this. It's much simpler that writing your own sort-merge.\nwith open('accountpartner.txt') as aFile:\n lookup = {}\n for line in aFile:\n lookup[line[:6]]= line\n\ndef make_groups( source ):\n group = []\n key= None\n for line in source:\n if line[:6] != key:\n ... | [
1
] | [] | [] | [
"iteration",
"python",
"text_parsing",
"text_processing"
] | stackoverflow_0005759772_iteration_python_text_parsing_text_processing.txt |
Q:
cheetah parsing error trying to change cheetahVarStartToken
I am writing a cheetah template and I want to change the cheetahVarStartToken so that I can use the $ for javascript libraries in that section of code however when I run the template I am getting this error
ConfigParser.ParsingError: File contains parsi... | cheetah parsing error trying to change cheetahVarStartToken | I am writing a cheetah template and I want to change the cheetahVarStartToken so that I can use the $ for javascript libraries in that section of code however when I run the template I am getting this error
ConfigParser.ParsingError: File contains parsing errors:
[line 2]: u'\t\t\t cheetahVarStartToken = "%"\... | [
"That assignment must start in the first column, so remove the whitespace at the front of cheetahVarStartToken:\nThis works:\ncheetahVarStartToken = \"%\"\n\nThis blows up:\n cheetahVarStartToken = \"%\"\n\n ConfigParser.ParsingError: File contains parsing errors: <???>\n [line 2]: ' cheetahVarStartToken = \"%... | [
2
] | [] | [] | [
"cheetah",
"python",
"templates"
] | stackoverflow_0005759837_cheetah_python_templates.txt |
Q:
python: single-line cartesian product for-loop
Did you know you can do this?
>>> [(x,y) for x in xrange(2) for y in xrange(5)]
[(0, 0), (0, 1), (0, 2), (0, 3), (0, 4), (1, 0), (1, 1), (1, 2), (1, 3), (1, 4)]
It's neat. Is there a for loop version or can one only do this for list comprehensions?
EDIT: I think my q... | python: single-line cartesian product for-loop | Did you know you can do this?
>>> [(x,y) for x in xrange(2) for y in xrange(5)]
[(0, 0), (0, 1), (0, 2), (0, 3), (0, 4), (1, 0), (1, 1), (1, 2), (1, 3), (1, 4)]
It's neat. Is there a for loop version or can one only do this for list comprehensions?
EDIT: I think my question was misunderstood. I want to know if there i... | [
"Well there's no syntax for what you want, but there is itertools.product.\n>>> import itertools\n>>> for x, y in itertools.product([1,2,3,4], [5,6,7,8]): print x, y\n... \n1 5\n1 6\n1 7\n1 8\n[ ... and so on ... ]\n\n",
"That is an equivalent, more compact version of:\ndef values():\n for x in xrange(2):\n ... | [
10,
5
] | [] | [] | [
"for_loop",
"list_comprehension",
"python"
] | stackoverflow_0005759770_for_loop_list_comprehension_python.txt |
Q:
Using ParentClass.method(self, *args, **kwargs) or super(MyClass, self).method(*args, **kwargs)
When one has a class that inherits from a single class, what is the preferred, and most pythonic, way to call parent methods? There are two ways that I know of to call the parent method.
Option 1:
ParentClass.method(sel... | Using ParentClass.method(self, *args, **kwargs) or super(MyClass, self).method(*args, **kwargs) | When one has a class that inherits from a single class, what is the preferred, and most pythonic, way to call parent methods? There are two ways that I know of to call the parent method.
Option 1:
ParentClass.method(self, *args, **kwargs)
Option 2:
super(MyClass, self).method(*args, **kwargs)
Option 1 definitely seem... | [
"First of all, if you have old-style classes you need to use Option 1.\nIf not, it depends on the code:\n\nIf the superclass (or subclasses) uses super (or nothing), you can safely use super. This also means your subclsses must use super instead of Parent.method(self, ...).\nIf the superclass (or subclasses) uses t... | [
6
] | [] | [] | [
"python",
"syntax"
] | stackoverflow_0005760030_python_syntax.txt |
Q:
Python Zip-File, wildcards
I was wondering how I could tell Python to extract only ".txt" files from a zip folder, using a wildcard. This code works fine for me:
extractor.extract("\websitefiles\test.hmtl")"
How can I use this same code to extract all .txt files in that current directory? I was thinking somethin... | Python Zip-File, wildcards | I was wondering how I could tell Python to extract only ".txt" files from a zip folder, using a wildcard. This code works fine for me:
extractor.extract("\websitefiles\test.hmtl")"
How can I use this same code to extract all .txt files in that current directory? I was thinking something like this:
extractor.extract("... | [
"First, you need the file names list, using namelist().\nThen, you can filter the \"*.txt\" files with txtfiles = fnmatch.filter(fn_list,\"*.txt\")\nNow you can extract the files one by one:\nextracts = [ extractor.extract(txt) for txt in txtfiles ]\n\n",
"\nI just need python to extract .txt files in the current... | [
6,
4,
2,
1
] | [] | [] | [
"python"
] | stackoverflow_0005755408_python.txt |
Q:
looking for x-platform python console library
I'm a Python newbie.
I need something like Curses library for Python 2.6 or 3.1 to run on Windows and Linux without any code changes.
I need functions for colorizing text and background, for clearing screen, for reading key code without showing letter on screen and for... | looking for x-platform python console library | I'm a Python newbie.
I need something like Curses library for Python 2.6 or 3.1 to run on Windows and Linux without any code changes.
I need functions for colorizing text and background, for clearing screen, for reading key code without showing letter on screen and for moving text cursor to specidied position.
It must ... | [
"In case anyone out there is still looking for a curses solution on Windows, here is a site which has PDCurses-based builds of the standard Python curses module for Windows, and covers a pretty wide range: 32-bit and 64-bit, for Python versions 2.5, 2.6, 2.7, 3.1 and 3.2.\nPDCurses is \"a public domain curses libra... | [
3,
1,
0
] | [] | [] | [
"console",
"curses",
"python"
] | stackoverflow_0001585272_console_curses_python.txt |
Q:
Django, Boto, S3: Why am I not getting a response suddenly?
This has been driving me crazy and I can't figure out where the issue is. AWS is having issues right now, but this problem was happening before all that and continues to exhibit same behavior.
Summary: I have an admin field that uploads images to S3 and ... | Django, Boto, S3: Why am I not getting a response suddenly? | This has been driving me crazy and I can't figure out where the issue is. AWS is having issues right now, but this problem was happening before all that and continues to exhibit same behavior.
Summary: I have an admin field that uploads images to S3 and stores the path in the database. On a fresh apache restart, it w... | [
"Not sure by looking at your code. But, sounds like there might be connections that aren't getting closed? At any rate, why not work with:\nhttps://bitbucket.org/david/django-storages/wiki/S3Storage\n?\ndjango-storages has worked well for me.\n"
] | [
0
] | [] | [] | [
"amazon_s3",
"amazon_web_services",
"boto",
"django",
"python"
] | stackoverflow_0005759037_amazon_s3_amazon_web_services_boto_django_python.txt |
Q:
I'm trying to make a live chat with django and orbited but I keep getting errors
I'm following this tutorial on how to setup a simple django/orbited/stomp live chat, and I've followed everything exactly how he does it, and I've even copied all of his code, but I still get this one weird error that I don't understa... | I'm trying to make a live chat with django and orbited but I keep getting errors | I'm following this tutorial on how to setup a simple django/orbited/stomp live chat, and I've followed everything exactly how he does it, and I've even copied all of his code, but I still get this one weird error that I don't understand.
When I go to the website, I get an alert that just says "Error". When I look at wh... | [
"sounds like cross domain problems for the JS? You are running the dev server on 0.0.0.0 and orbited on 127.0.0.1. Could be it. How are you accessing the page with your web browser?\nTry running orbited and the django dev server on 0.0.0.0 and also using this ip to visit the page in your browser.\n"
] | [
0
] | [] | [] | [
"django",
"javascript",
"orbited",
"python",
"stomp"
] | stackoverflow_0005760088_django_javascript_orbited_python_stomp.txt |
Q:
Store 3 nearest coordinates
I have an XML file that contains a number of points with their longitude and latitude.
My python code at the moment gets the nearest point by simply looping through the XML file, finding the nearest, in miles or whatever, then comparing it with the previous closest point. If its nearer ... | Store 3 nearest coordinates | I have an XML file that contains a number of points with their longitude and latitude.
My python code at the moment gets the nearest point by simply looping through the XML file, finding the nearest, in miles or whatever, then comparing it with the previous closest point. If its nearer then I assign the variable the va... | [
"Here's a solution that will work for any number of points:\nclosest = points[:NUM_CLOSEST]\nclosest.sort()\nfor point in points[NUM_CLOSEST:]:\n if point.distance < closest[-1].distance:\n closest[-1] = point\n closest.sort()\n\nObviously, a bit pseudo-cody. The sort() calls will probably need an... | [
1,
1
] | [] | [] | [
"coordinates",
"geopy",
"gps",
"python",
"xml"
] | stackoverflow_0005759847_coordinates_geopy_gps_python_xml.txt |
Q:
Key to OpenGL. Java / Scala / Python
one topic that has always been of highest interest to me is 3D Programming. I've made several attempts at programming small games and never really successed. After experiences with DirectX and C++, XNA and C#, as well as Unity3d and C#, I would like to try OpenGL. Just being c... | Key to OpenGL. Java / Scala / Python | one topic that has always been of highest interest to me is 3D Programming. I've made several attempts at programming small games and never really successed. After experiences with DirectX and C++, XNA and C#, as well as Unity3d and C#, I would like to try OpenGL. Just being curious. When using C++ the way to go is rat... | [
"I have used JOGL in many of my 3D projects. Learning how to use a binding is not as important as learning the actual api. Using opengl in c and java are pretty much the same. The only thing that differs is the way you set up your rendering windows and buffers. I use netbeans ide with the opengl for netbeans plugin... | [
3,
0
] | [] | [] | [
"java",
"jogl",
"opengl",
"python",
"scala"
] | stackoverflow_0004403150_java_jogl_opengl_python_scala.txt |
Q:
Use python to check if dev_appserver is running on localhost
I have a script that I use to connect to localhost:8080 to run some commands on a dev_appserver instance. I use a combination of remote_api_stub and httplib.HTTPConnection. Before I make any calls to either api I want to ensure that the server is actuall... | Use python to check if dev_appserver is running on localhost | I have a script that I use to connect to localhost:8080 to run some commands on a dev_appserver instance. I use a combination of remote_api_stub and httplib.HTTPConnection. Before I make any calls to either api I want to ensure that the server is actually running.
What would be a "best practice" way in python to determ... | [
"This should do it:\nimport httplib\n\nNO_WEB_SERVER = 0\nWEB_SERVER = 1\nGAE_DEV_SERVER_1_0 = 2\ndef checkServer(host, port, try_only_ssl = False):\n hh = None\n connectionType = httplib.HTTPSConnection if try_only_ssl \\\n else httplib.HTTPConnection\n try:\n ... | [
2,
0,
0
] | [] | [] | [
"google_app_engine",
"http",
"python"
] | stackoverflow_0005757356_google_app_engine_http_python.txt |
Q:
Truly a beginner, assigning the multiple values to one variable in Python
I want to make an image for any user, that's not specific to one size, I came up with this. I'm new at this, can anyone let me know why this does not work?
blk = makeEmptyPicture(getWidth(pic)+30), getHeight(pic)+30), black)
A:
blk = makeE... | Truly a beginner, assigning the multiple values to one variable in Python | I want to make an image for any user, that's not specific to one size, I came up with this. I'm new at this, can anyone let me know why this does not work?
blk = makeEmptyPicture(getWidth(pic)+30), getHeight(pic)+30), black)
| [
"blk = makeEmptyPicture(getWidth(pic)+30), getHeight(pic)+30), black)\nIt probably doesn't work because your parens aren't balanced. You have 3 open-parens and 5 close-parens.\nPerhaps this is what you meant instead?\nblk = makeEmptyPicture(getWidth(pic)+30, getHeight(pic)+30, black)\n\n",
"Try This: \nblk = make... | [
6,
3
] | [] | [] | [
"jes",
"jython",
"python"
] | stackoverflow_0005760360_jes_jython_python.txt |
Q:
Python range() builtin function, erm... malfunctioning with Django
What, if anything, is wrong with this line of python code:
daterange = [begin + timedelta(n) for n in range((end - begin).days)]
Where begin and end are datetime.date objects with valid values.
I'm using this in a Django view to process some data,... | Python range() builtin function, erm... malfunctioning with Django | What, if anything, is wrong with this line of python code:
daterange = [begin + timedelta(n) for n in range((end - begin).days)]
Where begin and end are datetime.date objects with valid values.
I'm using this in a Django view to process some data, but everytime the view this is in gets called I get the following error... | [
"There's nothing wrong with Django. You create a local variable range in the same scope (by assigning one). For instance range = None in the very last line of a function makes Python consider an occurrence of range in the first line of the same function a reference to that local variable. Since it doesn't have a va... | [
11
] | [] | [] | [
"built_in",
"date_range",
"django",
"python"
] | stackoverflow_0005760378_built_in_date_range_django_python.txt |
Q:
How do I check a field name from a Django form in html?
I have a Django form that contains several fields I am looping through. I want to branch the code if the field is the "comment" field, something like this:
{% for field in form.visible_fields %}
{% if field == form.fields.comment %}
<do something... | How do I check a field name from a Django form in html? | I have a Django form that contains several fields I am looping through. I want to branch the code if the field is the "comment" field, something like this:
{% for field in form.visible_fields %}
{% if field == form.fields.comment %}
<do something>
{% else %}
<do something else>
{% endif %}
... | [
"I believe it would be:\n{% if field.field == form.fields.comment %}\n\n"
] | [
5
] | [] | [] | [
"django",
"forms",
"python"
] | stackoverflow_0005760568_django_forms_python.txt |
Q:
Building Python extension module with distutils
I'm using distutils to build a Python extension module written in C++. The problem I have is that in order to compile the extension module, I need to link with a certain shared library. This requires setting an additional compiler flag. So, I searched through the ... | Building Python extension module with distutils | I'm using distutils to build a Python extension module written in C++. The problem I have is that in order to compile the extension module, I need to link with a certain shared library. This requires setting an additional compiler flag. So, I searched through the Python docs and found out about the extra_compile_arg... | [
"There's actually a special option for that.\nFor example:\nlibraries=[\"rt\"]\n\nYou leave off the option and lib parts. \n",
"One of the purposes of distutils is to make your code not dependent on a single compiler. Your \"-l somelib\" looks like it's meant to work with GCC (even though it should be \"-lsomelib... | [
6,
3
] | [] | [] | [
"c++",
"distutils",
"gcc",
"python"
] | stackoverflow_0005760356_c++_distutils_gcc_python.txt |
Q:
Soap call in Python
I tried to call a soap service. My call is success but its returns empty value.Below i attached my soap request and response schema. Its takes 1d array as input and return that array.
Request Schema
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSch... | Soap call in Python | I tried to call a soap service. My call is success but its returns empty value.Below i attached my soap request and response schema. Its takes 1d array as input and return that array.
Request Schema
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="... | [
"Here's a working version that uses suds client:\n#!/usr/bin/env python\nfrom suds.xsd.doctor import Import, ImportDoctor\nfrom suds.client import Client\n\n# enable logging to see transmitted XML\nimport logging\nlogging.basicConfig(level=logging.INFO)\nlogging.getLogger('suds.client').setLevel(logging.DEBUG)\n\n#... | [
11
] | [] | [] | [
"python",
"soap",
"soappy"
] | stackoverflow_0005752923_python_soap_soappy.txt |
Q:
Reading data from serial port (COM3) using pyserial module on Windows XP
Before going into the problem, here is some hardware/software information:
Device accessed: Ohaus Scout Pro Digital Weight Machine (product link)
Interface used: USB (product link)
Serial Port: COM3
OS: WinXP
Python Version: Activestate Pytho... | Reading data from serial port (COM3) using pyserial module on Windows XP | Before going into the problem, here is some hardware/software information:
Device accessed: Ohaus Scout Pro Digital Weight Machine (product link)
Interface used: USB (product link)
Serial Port: COM3
OS: WinXP
Python Version: Activestate Python 2.7
pyserial version: 2.5
Python recognized this serial port and had no prob... | [
"The baudrate is missing. You must specify baudrate. Most serial devices can not tolerate a wrong communication speed.\n"
] | [
2
] | [] | [] | [
"pyserial",
"python",
"usb",
"windows_xp"
] | stackoverflow_0005602349_pyserial_python_usb_windows_xp.txt |
Q:
How can I make this code work faster ? (searching large corpus of text for large words)
in Python, I have created a text generator that acts on certain parameters but my code is -at most of the time- slow and performs below my expectations. I expect one sentence per every 3-4 minutes but it fails to comply if the ... | How can I make this code work faster ? (searching large corpus of text for large words) | in Python, I have created a text generator that acts on certain parameters but my code is -at most of the time- slow and performs below my expectations. I expect one sentence per every 3-4 minutes but it fails to comply if the database it works on is large -I use the project Gutenberg's 18-book corpus and I will create... | [
"I think my first advice must be: Think carefully about what your routines do, and make sure the name describes that. Currently you have things like:\n\narraySorter which neither deals with arrays nor sorts (it's an implementation of nub)\nfindLongestWord which counts things or selects words by criteria not present... | [
4,
1
] | [] | [] | [
"optimization",
"performance",
"python",
"time"
] | stackoverflow_0005759959_optimization_performance_python_time.txt |
Q:
How can I change values for a section of a numpy array?
My question is a little more specific than that actually. Consider the following arrays:
from numpy import zeros, ones
array1 = ones((3, 3), bool)
array1[0][0] = 0
array1[0][2] = 0
array1[2][0] = 0
array1[2][2] = 0
array2 = zeros((12, 12), bool)
Now what I... | How can I change values for a section of a numpy array? | My question is a little more specific than that actually. Consider the following arrays:
from numpy import zeros, ones
array1 = ones((3, 3), bool)
array1[0][0] = 0
array1[0][2] = 0
array1[2][0] = 0
array1[2][2] = 0
array2 = zeros((12, 12), bool)
Now what I'm looking for is a way that I can refer to a 2 dimensional p... | [
"The output from an example using floats seems easier to understand:\n>>> a1 = numpy.ones((3, 3))\n>>> a2 = numpy.ones((12, 12))\n>>> a2[:3,:3] += a1\n>>> a2\narray([[ 2., 2., 2., 1., 1., 1., 1., 1., 1., 1., 1., 1.],\n [ 2., 2., 2., 1., 1., 1., 1., 1., 1., 1., 1., 1.],\n [ 2., 2.,... | [
5,
2
] | [] | [] | [
"arrays",
"numpy",
"python",
"slice"
] | stackoverflow_0005760862_arrays_numpy_python_slice.txt |
Q:
Django python can't set the admin default design to my interface
I have tried Django for a few days, and I'm trying to set up a production project with apache.
I have followed the official tutorial at
http://docs.djangoproject.com/en/1.3/intro/tutorial01/
Everything works just fine with the development server but ... | Django python can't set the admin default design to my interface | I have tried Django for a few days, and I'm trying to set up a production project with apache.
I have followed the official tutorial at
http://docs.djangoproject.com/en/1.3/intro/tutorial01/
Everything works just fine with the development server but with apache, I lose every admin style.
I have read similar posts for t... | [
"This is definitely an Apache issue. Your Alias is outside of your DocumentRoot, but you're not specifying access to it:\nhttp://httpd.apache.org/docs/2.0/mod/mod_alias.html#alias\nP.S.:\nIf you don't use a tool like Firebug, you could enter the URL of let's say one of the admin css files, to see in your browser wh... | [
0,
0
] | [] | [] | [
"django_admin",
"python"
] | stackoverflow_0005721664_django_admin_python.txt |
Q:
I am installing python 3 on snow leopard, what am I installing exactly?
I'm having difficulty installing python 3 on snow leopard.
I'm having difficulty because I have no idea what I am installing. (I do understand that python is a language, and that it uses a virtual machine)
Where can I get an overview of all th... | I am installing python 3 on snow leopard, what am I installing exactly? | I'm having difficulty installing python 3 on snow leopard.
I'm having difficulty because I have no idea what I am installing. (I do understand that python is a language, and that it uses a virtual machine)
Where can I get an overview of all the parts that make up working installation of python and how they need to be c... | [
"There is normally no need to build Python on Mac OS X from source. If you want the most recent Python 3, download and install one of the two official Python 3.2 installers for OS X from python.org here. The Python installers from python.org install a framework build of Python 3 rooted at\n/Library/Frameworks/Pyth... | [
3,
0
] | [] | [] | [
"osx_snow_leopard",
"python",
"python_3.x"
] | stackoverflow_0005760739_osx_snow_leopard_python_python_3.x.txt |
Q:
What does GAE mean by unbound method put() must be called with Movie instance as first argument
First
Error:
ERROR 2011-04-22 23:25:15,513 __init__.py:395] unbound method put() must be called with Movie instance as first argument (got nothing instead)
Traceback (most recent call last):
File "C:\Program Files ... | What does GAE mean by unbound method put() must be called with Movie instance as first argument | First
Error:
ERROR 2011-04-22 23:25:15,513 __init__.py:395] unbound method put() must be called with Movie instance as first argument (got nothing instead)
Traceback (most recent call last):
File "C:\Program Files (x86)\Google\google_appengine\google\appengine\ext\webapp\__init__.py", line 515, in __call__
han... | [
"Change it from\nmovie = Movie\n\nto\nmovie = Movie()\n\nYou need to actually make an instance of the Movie class, which is what Movie() does. (The key word in the error message you got was \"Movie instance\".)\n"
] | [
6
] | [] | [] | [
"google_app_engine",
"google_cloud_datastore",
"python"
] | stackoverflow_0005761063_google_app_engine_google_cloud_datastore_python.txt |
Q:
Should I use numpy (or pylab) as a python environment by using `from numpy import *`?
I use pylab (more specifically numpy) in all of my python programs. The exceptions are very rare, if any. So far, I have taken the habit of importing numpy in the following way:
from numpy import *
This has the advantage of mak... | Should I use numpy (or pylab) as a python environment by using `from numpy import *`? | I use pylab (more specifically numpy) in all of my python programs. The exceptions are very rare, if any. So far, I have taken the habit of importing numpy in the following way:
from numpy import *
This has the advantage of making it look like numpy was part of python from the beginning. Is there something bad in the... | [
"\nUsing from numpy import * changes the behavior of any, all and\nsum. For example,\nany([[False]])\n# True\nall([[True, False], [False, False]])\n# True\nsum([[1,2],[3,4]], 1) \n# TypeError: unsupported operand type(s) for +: 'int' and 'list'\n\nWhereas, if you use from numpy import * then values are completely d... | [
19,
12,
2,
2,
2
] | [] | [] | [
"coding_style",
"numpy",
"python"
] | stackoverflow_0005748895_coding_style_numpy_python.txt |
Q:
Checking if string element is present in a list with Python?
I have the following piece of code:
self.ignore_dir_extensions = ['xcodeproj']
item = repr(extension.split('/')[0])
print "String: " + item
if item in self.ignore_dir_extensions:
print "Available: " + item
Let's say I have this output:
String: 'x... | Checking if string element is present in a list with Python? | I have the following piece of code:
self.ignore_dir_extensions = ['xcodeproj']
item = repr(extension.split('/')[0])
print "String: " + item
if item in self.ignore_dir_extensions:
print "Available: " + item
Let's say I have this output:
String: 'xcodeproj'
Expected output:
String: 'xcodeproj'
Available: 'xcodep... | [
"Try the following:\nself.ignore_dir_extensions = ['xcodeproj']\n\nitem = extension.split('/')[0]\n\nprint \"String: \" + repr(item)\n\nif item in self.ignore_dir_extensions:\n print \"Available: \" + repr(item)\n\nYou do not want to have item be the result of repr(), because repr() on a string will add quotes, ... | [
3,
3,
0,
0
] | [] | [] | [
"python"
] | stackoverflow_0005761009_python.txt |
Q:
Bad auto completion with python on pydev?
I began learning and loving python about a month ago. Dive into python, django and now Tornado is the path i followed during this time.
I chose pydev as an IDE since it seems to be the most up to date and i wanted to come back to eclipse since i'm using Netbeans for php an... | Bad auto completion with python on pydev? | I began learning and loving python about a month ago. Dive into python, django and now Tornado is the path i followed during this time.
I chose pydev as an IDE since it seems to be the most up to date and i wanted to come back to eclipse since i'm using Netbeans for php and Java.
My question is the following:
When i wr... | [
"First make sure your interpreter is set up correctly.\nWindow | Preferences | Pydev | Interpreter - Python\n\nI use cpython on linux so my interpreter is\n cpython /usr/bin/python25\n\nUnder Libraries, make sure all the standard PYTHONPATH stuff is in there:\nSystem Libs\n /usr/lib/python2.5\n /usr/lib/pyt... | [
1,
0,
0
] | [] | [] | [
"pydev",
"python"
] | stackoverflow_0002470121_pydev_python.txt |
Q:
Python: Convert email address to HTML link
I'm looking for a stand-alone python function that will take in a string and return a string with the email addresses converted to links.
Example:
>>>s = 'blah blah blah a@at.com blah blah blah'
>>>link(s)
'blah blah blah <a href="mailto:a@at.com">a@at.com</a> blah blah b... | Python: Convert email address to HTML link | I'm looking for a stand-alone python function that will take in a string and return a string with the email addresses converted to links.
Example:
>>>s = 'blah blah blah a@at.com blah blah blah'
>>>link(s)
'blah blah blah <a href="mailto:a@at.com">a@at.com</a> blah blah blah'
| [
"Something like this?\nimport re\nimport xml.sax.saxutils\n\ndef anchor_from_email_address_match(match):\n address = match.group(0)\n return \"<a href=%s>%s</a>\" % (\n xml.sax.saxutils.quoteattr(\"mailto:\" + address),\n xml.sax.saxutils.escape(address))\n\ndef replace_email_addresses_with_anch... | [
8,
2,
0
] | [] | [] | [
"email_validation",
"html",
"python",
"regex",
"string"
] | stackoverflow_0005761090_email_validation_html_python_regex_string.txt |
Q:
pywin32: EnumFontFamilies breaks python
To wit:
import win32gui
def enum_fonts(typeface=None):
hwnd = win32gui.GetDesktopWindow()
dc = win32gui.GetWindowDC(hwnd)
res = []
def callback(*args):
res.append(args)
win32gui.EnumFontFamilies(dc, typeface, callback)
win32gui.ReleaseDC(hwn... | pywin32: EnumFontFamilies breaks python | To wit:
import win32gui
def enum_fonts(typeface=None):
hwnd = win32gui.GetDesktopWindow()
dc = win32gui.GetWindowDC(hwnd)
res = []
def callback(*args):
res.append(args)
win32gui.EnumFontFamilies(dc, typeface, callback)
win32gui.ReleaseDC(hwnd, dc)
return res
res = enum_fonts()
for... | [
"Ah I will shoot myself. The callback has to return an integer - 0 to stop iterating, non-zero to continue. This works fine:\ndef enum_fonts(typeface=None):\n hwnd = win32gui.GetDesktopWindow()\n dc = win32gui.GetWindowDC(hwnd)\n\n res = []\n def callback(*args):\n res.append(args)\n retur... | [
3
] | [] | [] | [
"python",
"pywin32",
"winapi",
"windows"
] | stackoverflow_0005760594_python_pywin32_winapi_windows.txt |
Q:
create a global function in python
In python how can I create a function that can be global an used in all classes that are called?
Here is an example:
import configparser
import os
import sys
from datetime import datetime
from ftplib import FTP
def notify(msg):
echo = True
log = True
if echo:
... | create a global function in python | In python how can I create a function that can be global an used in all classes that are called?
Here is an example:
import configparser
import os
import sys
from datetime import datetime
from ftplib import FTP
def notify(msg):
echo = True
log = True
if echo:
print(msg)
if log:
f = ope... | [
"Put notify() in a utility module and have all the other modules import it.\n"
] | [
7
] | [] | [] | [
"global",
"global_variables",
"python"
] | stackoverflow_0005761408_global_global_variables_python.txt |
Q:
Python: Why does my SMTP script freeze my computer?
So I wrote a little multithreaded SMTP program. The problem is every time I run it, it freezes the computer shortly after. The script appears to still work, as my network card is still lighting up and the emails are received, but in some cases it will lock up c... | Python: Why does my SMTP script freeze my computer? | So I wrote a little multithreaded SMTP program. The problem is every time I run it, it freezes the computer shortly after. The script appears to still work, as my network card is still lighting up and the emails are received, but in some cases it will lock up completely and stop sending the emails.
Here's a link to m... | [
"First, you're using popen which creates subprocesses, ie. processes not threads. I'll assume this is what you meant.\nMy guess would be that the program gets stuck in a loop where it generates processes continuously, which the OS will probably dislike. (That kind of thing is known as a forkbomb which is a good way... | [
3
] | [] | [] | [
"freeze",
"multithreading",
"python",
"smtp"
] | stackoverflow_0005761470_freeze_multithreading_python_smtp.txt |
Q:
perl in-place sort lines in a text file
I wish to modify a text file by sorting each line based on a given key and save the old file as a backup. The key is a numeric character contained in each line.
Is there a simple script to get this done, preferably in-place?
Thanks!
A:
There are in-place sorting algorit... | perl in-place sort lines in a text file | I wish to modify a text file by sorting each line based on a given key and save the old file as a backup. The key is a numeric character contained in each line.
Is there a simple script to get this done, preferably in-place?
Thanks!
| [
"There are in-place sorting algorithms with O(n log n) complexity such as Heapsort, but I don't see why you would want to use that rather than something simple such as the Unix sort command. Unless you have stringent performance requirements or huge datasets... but then, perl and python probably aren't the best too... | [
1,
1,
0
] | [] | [] | [
"perl",
"python"
] | stackoverflow_0005760733_perl_python.txt |
Q:
AppEngine and Django: including a template file
As the title suggests, I'm using Google App Engine and Django.
I have quite a bit of identical code across my templates and would like to reduce this by including template files. So, in my main application directory I have the python handler file, the main template, ... | AppEngine and Django: including a template file | As the title suggests, I'm using Google App Engine and Django.
I have quite a bit of identical code across my templates and would like to reduce this by including template files. So, in my main application directory I have the python handler file, the main template, and the template I want to include in my main templat... | [
"First, you should consider using template inheritance rather than the include tag, which is often appropriate but sometimes far inferior to template inheritance.\nUnfortunately, I have no experience with App Engine, but from my experience with regular Django, I can tell you that you need to set your TEMPLATE_DIRS ... | [
3,
1,
1,
0
] | [] | [] | [
"django",
"google_app_engine",
"include",
"python",
"templates"
] | stackoverflow_0000470008_django_google_app_engine_include_python_templates.txt |
Q:
Pyramid authorization for stored items
I'm trying to create an authorization policy that takes "item" ownership into account. For example some user X "owns" items A, B, C. Those are accessed via URLs like /item/{item}/some_options.
How can I get the information about {item} to the authorization policy object (perm... | Pyramid authorization for stored items | I'm trying to create an authorization policy that takes "item" ownership into account. For example some user X "owns" items A, B, C. Those are accessed via URLs like /item/{item}/some_options.
How can I get the information about {item} to the authorization policy object (permits() call)? Is putting additional informati... | [
"You can do this using the ACLAuthorizationPolicy combined with URL Dispatch by using a custom resource tree designed for this purpose.\nFor example, you have permissions for Foo objects, and permissions for Bar objects. These ACLs can be found by traversing the resource tree using the urls:\n/foos/{obj}\n/bars/{ob... | [
52
] | [] | [] | [
"authorization",
"policy",
"pyramid",
"python"
] | stackoverflow_0005761617_authorization_policy_pyramid_python.txt |
Q:
Decrypting pdf password with python
Is there a way to find the author password to a pdf document (preferably with python), that prevents editing/printing? I've found this but its from 2004 and I cannot seem to get it working.
A:
check this script from Anand B Pillai
# -- coding: utf-8
""" A simple PDF accessib... | Decrypting pdf password with python | Is there a way to find the author password to a pdf document (preferably with python), that prevents editing/printing? I've found this but its from 2004 and I cannot seem to get it working.
| [
"check this script from Anand B Pillai\n# -- coding: utf-8\n\n\"\"\" A simple PDF accessibility checking WAM\n\nCreation: Anand B Pillai <abpillai at gmail dot com> April 27 2007\n\nModification History\n\nAnand April 27 07 Added more exception handling. Fixed a\n problem in pyPdf which was not... | [
1
] | [] | [] | [
"pdf",
"python"
] | stackoverflow_0005761931_pdf_python.txt |
Q:
How can I distinguish between an open tag and a closed tag in the findPrevious function in BeautifulSoup?
I want to find if a searched item is contained within a table. I use the following code:
tableprevious = foundtext.findPrevious('table')
However, this code will refer to either
<table> or </table>
and doesn... | How can I distinguish between an open tag and a closed tag in the findPrevious function in BeautifulSoup? | I want to find if a searched item is contained within a table. I use the following code:
tableprevious = foundtext.findPrevious('table')
However, this code will refer to either
<table> or </table>
and doesn't make it possible to distinguish if the foundtext is already in a table. Any ideas?
| [
"Try the findParent() method. If an item is contained in a table, it will have a table tag as an ancestor. Example:\nfrom BeautifulSoup import BeautifulSoup\n\nhtml = '<table><tr><td><b>In table</b></td></tr></table><b>Not in table</b>'\nsoup = BeautifulSoup(html)\nitems = soup('b')\nfor item in items:\n if it... | [
1
] | [] | [] | [
"beautifulsoup",
"python",
"tags"
] | stackoverflow_0005761884_beautifulsoup_python_tags.txt |
Q:
Python recursion limit
So I understand the reason for the recursion limit of 1000. I want to run a script continuously, but am I right understanding that eventually the recursion limit will be reached (even if I set it higher) and Python will break?
In the scheme of things, its not a big deal, because I could get... | Python recursion limit | So I understand the reason for the recursion limit of 1000. I want to run a script continuously, but am I right understanding that eventually the recursion limit will be reached (even if I set it higher) and Python will break?
In the scheme of things, its not a big deal, because I could get the OS to keep re-starting ... | [
"CPython has no optimizations for recursion, so you really want to avoid deeply-recursive code in favor of regular loops:\ndef main():\n while True:\n all_files = getFiles(LOC_DIR)\n files = []\n for f in all_files:\n if checkExt(f):\n files.append(f)\n if le... | [
7,
1,
0
] | [] | [] | [
"python",
"recursion"
] | stackoverflow_0005762301_python_recursion.txt |
Q:
Is this iteration necessary?
Hi my usage of get_serving_url is serverside now I wonder if this can be done in template instead of iterating serverside?
class Ad(GeoModel,search.SearchableModel):
.......
class Image(db.Model): #migrate to blobstore
reference = db.ReferenceProperty(Ad, collection_name='m... | Is this iteration necessary? | Hi my usage of get_serving_url is serverside now I wonder if this can be done in template instead of iterating serverside?
class Ad(GeoModel,search.SearchableModel):
.......
class Image(db.Model): #migrate to blobstore
reference = db.ReferenceProperty(Ad, collection_name='matched_images', verbose_name="Titl... | [
"I´d suggest you store the image url in the database. This url´s are static, and whenever you do a get_serving_url theres a lot of CPU time involved. I saw a drastic improvement in my own app when I did this. Also, by doing so, your initial problem will be solved immediately.\n"
] | [
2
] | [] | [] | [
"google_app_engine",
"python"
] | stackoverflow_0005761208_google_app_engine_python.txt |
Q:
global question (python)
I have the code:
from Tkinter import *
admin = Tk()
a = 1
def up():
global a
a += 1
def upp():
up()
print a
print 'its ',a
buttton = Button(admin, text='up', command=upp)
buttton.pack()
mainloop()
I want to have the "its ",a go up each time i press the button. so kind of... | global question (python) | I have the code:
from Tkinter import *
admin = Tk()
a = 1
def up():
global a
a += 1
def upp():
up()
print a
print 'its ',a
buttton = Button(admin, text='up', command=upp)
buttton.pack()
mainloop()
I want to have the "its ",a go up each time i press the button. so kind of replay the code so that, its ... | [
"I tested this:\nfrom Tkinter import *\nimport itertools\n\nadmin = Tk()\na = itertools.count(1).next\n\n\ndef upp():\n print a()\n\nbuttton = Button(admin, text='up', command=upp)\nbuttton.pack()\nmainloop()\n\nThis will start a at a value of 1 and each time its printed it will add one more. So the first time y... | [
4,
1
] | [] | [] | [
"python",
"tkinter"
] | stackoverflow_0005762620_python_tkinter.txt |
Q:
Reducing the following lines of PhotoImage code to as few lines as possible
The goal is to reduce the following code to as few lines (and as few characters) of code as possible. It doesn't need to be 'readable' or even 'pythonic', just short and sweet. this ones more for fun.
self.BlueEgg = PhotoImage(file="assets... | Reducing the following lines of PhotoImage code to as few lines as possible | The goal is to reduce the following code to as few lines (and as few characters) of code as possible. It doesn't need to be 'readable' or even 'pythonic', just short and sweet. this ones more for fun.
self.BlueEgg = PhotoImage(file="assets/blueegg.gif")
self.PolkaEgg = PhotoImage(file="assets/polkaegg.gif")
self.RedEgg... | [
"The only thing that changes is the type of egg, which changes the attribute on self and the filename. So...\ntypes = ('Blue', 'Polka', 'Red', 'Stripe', 'Yellow', 'Purple', 'Pink', 'Orange', 'Crazy', 'Plain')\nfor t in types:\n setattr(self, '%sEgg' % t, PhotoImage(file='assets/%segg.gif' % t.lower()))\n\n",
"... | [
3,
2
] | [] | [] | [
"metaprogramming",
"python"
] | stackoverflow_0005760585_metaprogramming_python.txt |
Q:
wxPython: Handling drag-and-drop in a parent object - problem with event propagation
I have a wxPython program where I want to be able to drag groups of controls around to reorder them. Each group of controls is on a panel, and I want the panel object to handle the drag-and-drop.
Currently it works if you click a... | wxPython: Handling drag-and-drop in a parent object - problem with event propagation | I have a wxPython program where I want to be able to drag groups of controls around to reorder them. Each group of controls is on a panel, and I want the panel object to handle the drag-and-drop.
Currently it works if you click and drag on the panel itself, but it doesn't work if you click on any control inside the pa... | [
"I realize this is rather late, but in case it's still helpful to someone:\nI've done this in the code in my (related) question: \nimport wx\n\napp = wx.App(False)\nd = {}\n\ndef wMouseDown(e):\n print \"!!!\", e.GetEventObject()\n\ndef MouseDown(e): \n o = e.GetEventObject()\n sx,sy = pa... | [
2,
1
] | [] | [] | [
"drag_and_drop",
"python",
"wxpython"
] | stackoverflow_0001877402_drag_and_drop_python_wxpython.txt |
Q:
Python: What's wrong with this Fibonacci function?
I tried to write a simple python function which should return the list of fib numbers upto some specified max. But I am getting this error. I can't seem to find out what I am doing wrong.
def fib(a,b,n):
f = a+b
if (f > n):
return []
return [... | Python: What's wrong with this Fibonacci function? | I tried to write a simple python function which should return the list of fib numbers upto some specified max. But I am getting this error. I can't seem to find out what I am doing wrong.
def fib(a,b,n):
f = a+b
if (f > n):
return []
return [f].extend(fib(b,f,n))
>>>fib(0,1,10)
Traceback (most re... | [
"list.extend extends a list in-place. You can use the + operator to concatenate two lists together.\nHowever, your code isn't particularly Pythonic. You should use a generator for infinite sequences, or, as a slight improvement over your code:\ndef fib(a,b,n):\n data = []\n f = a+b\n if (f > n):\n r... | [
9,
1
] | [] | [] | [
"fibonacci",
"iterator",
"python"
] | stackoverflow_0005763143_fibonacci_iterator_python.txt |
Q:
generate images from swf
Is there any library/module available with which i can generate images from a swf file?
The problem i am trying to solve is: I want to create a pdf from a web page and i am having problems in doing that when the web page has swf (question in stackoverflow)
I am thinking if i am able to re... | generate images from swf | Is there any library/module available with which i can generate images from a swf file?
The problem i am trying to solve is: I want to create a pdf from a web page and i am having problems in doing that when the web page has swf (question in stackoverflow)
I am thinking if i am able to read a swf and write out an imag... | [
"In fact, that is quite a hard task. I've spent hours looking for a program that could fulfill such a task. However, I eventually only found one. It isn't open-source but would really help you I guess.\nFlash Animation Source can output all frames of a SWF file. It uses a DirectShow filter to do so. Therefore, a Wi... | [
1
] | [] | [] | [
"perl",
"php",
"python"
] | stackoverflow_0005760089_perl_php_python.txt |
Q:
How can I get a file to autorun before I run any command in ipython?
I have a python file that holds a bunch of functions that I'm continually modifying and then testing in ipython. My current workflow is to run "%run myfile.py" before each command. However, ideally, I'd like that just to happen automatically. ... | How can I get a file to autorun before I run any command in ipython? | I have a python file that holds a bunch of functions that I'm continually modifying and then testing in ipython. My current workflow is to run "%run myfile.py" before each command. However, ideally, I'd like that just to happen automatically. Is that possible?
| [
"I can't find any elegant way. This is the ugly way. Run:\nrlwrap awk '{print \"%run myfile.py\"} {print} {fflush()}' |ipython\n\nThis reads from STDIN, but prints the command you wanted before each command. fflush is there to disable buffering and pass things to ipython immediately. rlwrap is there to keep the rea... | [
2,
2
] | [] | [] | [
"ipython",
"python"
] | stackoverflow_0005761276_ipython_python.txt |
Q:
How to configure app.yaml to support urls like /user/?
I do the following
- url: /user/.*
script: script.py
And the following handling in script.py:
class GetUser(webapp.RequestHandler):
def get(self):
logging.info('(GET) Webpage is opened in the browser')
self.response.out.write('here I sho... | How to configure app.yaml to support urls like /user/? | I do the following
- url: /user/.*
script: script.py
And the following handling in script.py:
class GetUser(webapp.RequestHandler):
def get(self):
logging.info('(GET) Webpage is opened in the browser')
self.response.out.write('here I should display user-id value')
application = webapp.WSGIApplic... | [
"In app.yaml you want to do something like: \n- url: /user/\\d+\n script: script.py\n\nAnd then in script.py:\nclass GetUser(webapp.RequestHandler):\n def get(self, user_id):\n logging.info('(GET) Webpage is opened in the browser')\n self.response.out.write(user_id)\n # and maybe you would ... | [
6
] | [] | [] | [
"google_app_engine",
"python"
] | stackoverflow_0005763425_google_app_engine_python.txt |
Q:
How to get span value using python,BeautifulSoup
I am using BeautifulSoup for the first time and trying to collect several data such as email,phone number, and mailing address from a soup object.
Using regular expressions, I can identify the email address. My code to find the email is:
def get_email(link):
mail_li... | How to get span value using python,BeautifulSoup | I am using BeautifulSoup for the first time and trying to collect several data such as email,phone number, and mailing address from a soup object.
Using regular expressions, I can identify the email address. My code to find the email is:
def get_email(link):
mail_list = []
for i in link:
a = str(i)
emai... | [
"The most obvious problem with your code is that you're turning the object representing the link back into HTML and then parsing it with a regular expression again - that ignores much of the point of using BeautifulSoup in the first place. You might need to use a regular expression to deal with the contents of the... | [
4
] | [] | [] | [
"beautifulsoup",
"python"
] | stackoverflow_0005762975_beautifulsoup_python.txt |
Q:
What would be a good python library to use to write a portable version of pacman with nice graphics?
I basically want to make a clone of the classic game Pacman using Python. I would like to keep all the original graphics, sounds, etc. Perhaps being able to have the game in windowed mode would be useful.
With Java... | What would be a good python library to use to write a portable version of pacman with nice graphics? | I basically want to make a clone of the classic game Pacman using Python. I would like to keep all the original graphics, sounds, etc. Perhaps being able to have the game in windowed mode would be useful.
With Java I would just use Swing and be done with it. But I'd really like to use Python and make it possible for th... | [
"Try PyQt4. Qt isn't only meant for games but it has a QGraphicsView and an OpenGL widget where you can render from Python.\n",
"You could do this with Tkinter about as easily (or easier) than most other toolkits. Since pac-man graphics set the bar pretty low you could code this all by using the canvas widget. Th... | [
2,
1,
0
] | [] | [] | [
"pacman",
"pygame",
"python"
] | stackoverflow_0005743946_pacman_pygame_python.txt |
Q:
grid not working as expected in Python using Tkinter
I am going through a book which says I must use the following code to create a GUI with a label on the top left (co-ordinate (0,0)). In the book, the author prints a screenshot of the GUI and the label it is at (0,0) as expected. But when I run it it is in the c... | grid not working as expected in Python using Tkinter | I am going through a book which says I must use the following code to create a GUI with a label on the top left (co-ordinate (0,0)). In the book, the author prints a screenshot of the GUI and the label it is at (0,0) as expected. But when I run it it is in the center not matter how I change the row,column, columnspan a... | [
"The problem is, you are using a very old version of python and Tkinter. If you upgrade, the code you posted will work fine.\n"
] | [
0
] | [] | [] | [
"grid",
"python",
"tkinter"
] | stackoverflow_0005758984_grid_python_tkinter.txt |
Q:
rc.local and python script
I'm trying to start a script on bootup on a Ubuntu Server 10.10 machine.
The relevant parts of my rc.local look like this:
/usr/local/bin/python3.2 "/root/Advantage/main.py" >> /startuplogfile
exit 0
If I run ./rc.local from /etc everything works just fine and it writes the following in... | rc.local and python script | I'm trying to start a script on bootup on a Ubuntu Server 10.10 machine.
The relevant parts of my rc.local look like this:
/usr/local/bin/python3.2 "/root/Advantage/main.py" >> /startuplogfile
exit 0
If I run ./rc.local from /etc everything works just fine and it writes the following into /startuplogfile:
usage: main.... | [
"try to redirect stderr and stdout into the /startuplogfile like this : \n/usr/local/bin/python3.2 \"/root/Advantage/main.py\" >> /startuplogfile 2>&1\n\nyou will see if an error occurs\n",
"You definitely don't want to have that script world-writable. You're trying to automatically run it as root on bootup, but... | [
3,
3
] | [] | [] | [
"python",
"ubuntu",
"unix"
] | stackoverflow_0005763608_python_ubuntu_unix.txt |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.