Q_Id
int64
337
49.3M
CreationDate
stringlengths
23
23
Users Score
int64
-42
1.15k
Other
int64
0
1
Python Basics and Environment
int64
0
1
System Administration and DevOps
int64
0
1
Tags
stringlengths
6
105
A_Id
int64
518
72.5M
AnswerCount
int64
1
64
is_accepted
bool
2 classes
Web Development
int64
0
1
GUI and Desktop Applications
int64
0
1
Answer
stringlengths
6
11.6k
Available Count
int64
1
31
Q_Score
int64
0
6.79k
Data Science and Machine Learning
int64
0
1
Question
stringlengths
15
29k
Title
stringlengths
11
150
Score
float64
-1
1.2
Database and SQL
int64
0
1
Networking and APIs
int64
0
1
ViewCount
int64
8
6.81M
2,431,236
2010-03-12T07:56:00.000
2
1
1
1
python,py2exe,upx
2,433,251
1
false
0
0
I have experienced significant increases in start up time when UPX compressed executables are run on systems with certain virus scanners. I was only compressing single executables, but I expect that each compressed dll would add to the start time. Is it really necessary to use UPX? I can't imagine the space savings to be significant enough to be worth the trouble.
1
2
0
Are there any downsides to UPX-ing my 32-bit Python 2.6.4 development environment EXE/PYD/DLL files? The reason I'm asking is that I frequently use a custom PY2EXE script that UPX's copies of these files on every build. Yes, I could get fancy and try to cache UPXed files, but I think a simpler, safer, and higher performance solution would be for me to just UPX my Python 2.6.4 directory once and be done with it. Thoughts? Malcolm
Any downsides to UPX-ing my 32-bit Python 2.6.4 development environment EXE/PYD/DLL files?
0.379949
0
0
637
2,431,844
2010-03-12T10:02:00.000
1
0
0
0
python,qt,pyqt,signals,qtablewidget
2,432,210
3
false
0
1
It seems, that this is the only signal in QTableWidget at least for 4.6. You could post a feature request, but I don't know if it is accepted and you might wait for long time ;-) Maybe you could try to write a subclass of QTableWidget and emit own signals, when cell is changed internally. Anyway, disconnecting for the time of updating the cell isn't that bad, since you can't connect to specific signal.
2
4
0
i am using PyQt but my question is a general Qt one: I have a QTableWidget that is set up by the function updateTable. It writes the data from DATASET to the table when it is called. Unfortunately this causes my QTableWidget to emit the signal cellChanged() for every cell. The signal cellChanged() is connected to a function on_tableWidget_cellChanged that reads the contents of the changed cell and writes it back to DATASET. This is necessary to allow the user to change the data manually. So everytime the table is updated, its contents are written back to DATASET. Is there a way to distinguish if the cell was changed by the user or by updateTable? i thought of disconnecting on_tableWidget_cellChanged by updateTable temporarily but that seems to be a little dirty.
QTableWidget signal cellChanged(): distinguish between user input and change by routines
0.066568
0
0
5,819
2,431,844
2010-03-12T10:02:00.000
1
0
0
0
python,qt,pyqt,signals,qtablewidget
2,449,334
3
false
0
1
I would recommend changing from a QTableWidget to a QTableView with an appropriate model. From the sounds of it, you have a database or other data object holding and arranging the data anyway, so it would hopefully be fairly easy to do. This would then allow you to distinguish between edits (setData is called on your model) and updates (data is called on your model).
2
4
0
i am using PyQt but my question is a general Qt one: I have a QTableWidget that is set up by the function updateTable. It writes the data from DATASET to the table when it is called. Unfortunately this causes my QTableWidget to emit the signal cellChanged() for every cell. The signal cellChanged() is connected to a function on_tableWidget_cellChanged that reads the contents of the changed cell and writes it back to DATASET. This is necessary to allow the user to change the data manually. So everytime the table is updated, its contents are written back to DATASET. Is there a way to distinguish if the cell was changed by the user or by updateTable? i thought of disconnecting on_tableWidget_cellChanged by updateTable temporarily but that seems to be a little dirty.
QTableWidget signal cellChanged(): distinguish between user input and change by routines
0.066568
0
0
5,819
2,432,468
2010-03-12T11:55:00.000
1
0
0
0
python,gtk,pygtk,glade
2,432,881
1
true
0
1
You could be a bit clearer, it's not obvious what you do with your GtkEntry after creating it. The easiest thing would be to just add it to a Python list, so you can iterate over all created GtkEntry widgets later. Or, you could "tag" the widgets with something to make them identifiable, and iterate over the containing widgets (assuming you really do add the widget to a window or something).
1
0
0
On a click of a button named "Add Textbox" it calls a function which creates a single textbox using (gtk.Entry) function. So each time i click that button it creates a textbox. I have a submit button which should fetches all the values of the text boxes(say 10 textboxes) generated with the name of "entry". It works for one textbox but not for multiple. In php we can create dynamix textboxes mentioning as an array name=entry[]. Do we have similar functionality in python ? Enviroment : FC10 , Glade 3 , Python 2.5 , GTK.
Getting values from Multiple Text Entry using Pygtk and Python
1.2
0
0
1,035
2,432,792
2010-03-12T12:54:00.000
5
1
0
0
c++,python,c,performance,opencv
2,433,626
2
true
0
0
You've answered your own question pretty well. Most of the expensive computations should be within the OpenCV library, and thus independent of the language you use. If you're really concerned about efficiency, you could profile your code and confirm that this is indeed the case. If need be, your custom processing functions, if any, could be coded in C/C++ and exposed in python through the method of your choice (eg: boost-python), to follow the same approach. But in my experience, python works just fine as a "composition" tool for such a use.
2
1
1
I'm doing some prototyping with OpenCV for a hobby project involving processing of real time camera data. I wonder if it is worth the effort to reimplement this in C or C++ when I have it all figured out or if no significant performance boost can be expected. The program basically chains OpenCV functions, so the main part of the work should be done in native code anyway.
OpenCV performance in different languages
1.2
0
0
1,352
2,432,792
2010-03-12T12:54:00.000
0
1
0
0
c++,python,c,performance,opencv
2,470,491
2
false
0
0
OpenCV used to utilize IPP, which is very fast. However, OpenCV 2.0 does not. You might customize your OpenCV using IPP, for example color conversion routines.
2
1
1
I'm doing some prototyping with OpenCV for a hobby project involving processing of real time camera data. I wonder if it is worth the effort to reimplement this in C or C++ when I have it all figured out or if no significant performance boost can be expected. The program basically chains OpenCV functions, so the main part of the work should be done in native code anyway.
OpenCV performance in different languages
0
0
0
1,352
2,433,293
2010-03-12T14:21:00.000
1
0
0
0
python,telnet
2,433,355
2
true
0
0
Put tn.read_until("123", 2) in a loop.
1
0
0
I'm writing a simple script, that just connects to telnet port, listens everything on it, staying connected and when some string, for example '123' appears, script do something. I use tn.read_until("123", 2), but when '123' appears, script just disconnects. How to make it stay online?
EOL character in Linux and Windows
1.2
0
0
384
2,433,816
2010-03-12T15:41:00.000
3
0
1
0
python,exception-handling
2,433,856
2
true
0
0
I would say that "trapping" and "catching" an exception are the same thing: you have to trap/catch it to be able to handle it, but the act of trapping it is not the same as handling it. Trapping-but-not-handling = supressing, in other words. Handling implies that you actually do something with the information at your disposal: log it, throw it to the next level, perform some action if the exception is not entirely unexpected etc.etc. Or to put it another way, trapping an exception means that you have a code construct into which exception-al circumstances will flow, and where you can choose to handle the information that you find there.
1
2
0
I'm looking into exception handling in python and a blog post I read differentiated between trapping and handling an exception. Can someone explain the core difference between these two, both in python specifically and the overall conceptual difference? A google search for 'exception trapping handling' isn't super-useful.
What is the difference between trapping and handling an exception?
1.2
0
0
1,373
2,435,066
2010-03-12T18:59:00.000
23
0
1
0
python,python-3.x,introspection
5,876,453
3
false
0
0
The callable() builtin function from Py2.x was resurrected in python3.2.
1
13
0
I was studying introspection in Python, and as I was getting through basic examples, I found out that the callable built-in function is no longer available in Python 3.1. How can I check if a method is callable now? Thank you
What is the new way of checking "callable" methods in python 3.x?
1
0
0
4,173
2,435,281
2010-03-12T19:32:00.000
0
0
0
0
python,database,postgresql
2,435,639
1
true
0
0
To make sure we're on the same page, is the following correct? You're inserting the photo information into the Photo table immediately after the user uploads the photo but before he/she submits the form; When the user submits the form, you're inserting a row into the User table; One of the items in that row is information about the previously created photo entry. If so, you should be able to store the "path to photo" information in a Python variable until the user submits the form, and then use the value from that variable in your User-table insert.
1
0
0
Let's say I have an user registration form. In this form, I have the option for the user to upload a photo. I have an User table and Photo table. My User table has a "PathToPhoto" column. My question is how do I fill in the "PathToPhoto" column if the photo is uploaded and inserted into Photo table before the user is created? Another way to phrase my question is how to get the newly uploaded photo to be associated to the user that may or may not be created next. I'm using python and postgresql.
Database: storing data from user registration form
1.2
1
0
397
2,435,294
2010-03-12T19:34:00.000
0
0
0
0
python,ruby,client,size
2,435,731
1
false
0
0
Could you add a little more information and code to your example? Are you thinking about sock.recv_into() which takes a buffer and buffer size as arguments? Alternately, are you hitting a timeout issue by failing to have a keepalive on the Ruby side? Guessing in advance of knowledge.
1
0
0
We have server on Python and client + web service on Ruby. That works only if file from URL is less than 800 k. It seems like "socket.puts data" in a client works, but "output = socket.gets" - not. I think problem is in a Python part. For big files tests run "Connection reset by peer". Is it buffer size variable by default somewhere in a Python?
File size in Python server
0
0
1
183
2,435,470
2010-03-12T19:59:00.000
-1
0
0
0
python,pdf,qt4,pyqt4
2,435,561
3
false
0
1
what about okular? It is a full app, but it can always be call from another app.
1
8
0
I'm writing a Python+Qt4 application that would ideally need to pop up a window every once in a while, to display pdf documents and allow very basic operations, namely scrolling through the different pages and printing the document. I've found the reportLab to create pdf files, but nothing about pdf viewers. Does anyone knows anything that might help. i was really hoping for the existence of something like the QWebView widget... thanks in advance to all
pdf viewer for pyqt4 application?
-0.066568
0
0
6,219
2,436,578
2010-03-12T23:39:00.000
9
0
1
0
python,callable
2,436,587
3
true
0
0
They take parameters and return a result depending on those parameters. A callable is just an abstract form of a function resp an interface that defines that an object acts like a function (i.e. accepts parameters). As functions are first class objects, it is obvious that functions are callable objects. If you are talking about the __call__ method, this is just one of the many special methods with which you can overload the behavior of custom objects, e.g. for arithmetic operations or also defining what happens if you call an object. One idea why to use such is to have some kind of factory object that itself creates other objects.
2
12
0
What is the purpose of a callable object? What problems do they solve?
Why do we have callable objects in python?
1.2
0
0
7,287
2,436,578
2010-03-12T23:39:00.000
13
0
1
0
python,callable
2,436,614
3
false
0
0
Many kinds of objects are callable in Python, and they can serve many purposes: functions are callable, and they may carry along a "closure" from an outer function classes are callable, and calling a class gets you an instance of that class methods are callable, for function-like behavior specifically pertaining to an instance staticmethods and classmethods are callable, for method-like functionality when the functionality pertains to "a whole class" in some sense (staticmethods' usefulness is dubious, since a classmethod could do just as well;-) generators are callable, and calling a generator gets you an iterator object finally, and this may be specifically what you were asking about (not realizing that all of the above are objects too...!!!), you can code a class whose instances are callable: this is often the simplest way to have calls that update an instance's state as well as depend on it (though a function with a suitable closure, and a bound method, offer alternatives, a callable instance is the one way to go when you need to perform both calling and some other specific operation on the same object: for example, an object you want to be able to call but also apply indexing to had better be an instance of a class that's both callable and indexable;-). A great range of examples of the kind of "problems they solve" is offered by Python's standard library, which has many cases of each of the specific types I mention above.
2
12
0
What is the purpose of a callable object? What problems do they solve?
Why do we have callable objects in python?
1
0
0
7,287
2,436,787
2010-03-13T00:46:00.000
0
0
0
0
python,continuous-integration,hudson,pylint,pyflakes
34,396,655
3
false
0
0
The Violations plugin requires xml output from the various checkers This is wrong: Some checkers like "checkstyle" output XML, some others like "pylint" and "pep8" output "text" files with one record per line. The heading in Jenkins "XML filename pattern" is plain misleading.
2
8
0
We use Hudson for continuous integration with the Violations Plugin which parses our output from pylint. However, pylint is a bit too strict, and hard to configure. What we'd rather use is pyflakes which would give us the right level of "You're doing it wrong."
How would I start integrating pyflakes with Hudson
0
0
0
1,783
2,436,787
2010-03-13T00:46:00.000
1
0
0
0
python,continuous-integration,hudson,pylint,pyflakes
2,436,865
3
false
0
0
The Violations plugin requires xml output from the various checkers that it supports. I'm not familiar with pyflakes, but from my brief scan, it doesn't appear to support xml as an output type. So you'll have to post-process the pyflakes output before letting Violations try to parse it (or you could modify pyflakes and write your own Message output class). You'll probably want to capture the pylint output and use that to figure out the appropriate xml format that the Violations plugin likes.
2
8
0
We use Hudson for continuous integration with the Violations Plugin which parses our output from pylint. However, pylint is a bit too strict, and hard to configure. What we'd rather use is pyflakes which would give us the right level of "You're doing it wrong."
How would I start integrating pyflakes with Hudson
0.066568
0
0
1,783
2,436,927
2010-03-13T01:41:00.000
0
0
0
1
.net,python,windows-services,ironpython
2,539,346
3
true
0
0
I had to host a WCF in the windows service to allow it to be notified remotely. Just to keep deploying the solution as simple as possible. using the ServiceController would require the correct setup of permissions
1
1
0
What is the easiest way to ping/notify a .NET Windows Service? Do I have to use WCF for this? Or is there an easier way? I would like to be able to wake up the service using a Python (or an Iron Python) script from anywhere. Also is there a way I can be notified (by email) if that the service has stopped?
What is the easiest way to ping/notify a .NET Windows Service?
1.2
0
0
858
2,437,167
2010-03-13T03:31:00.000
4
0
0
0
python,scripting,command-prompt
2,437,395
2
false
1
0
Check assoc and ftype. If properly set, you can run a .py with arguments. > assoc .py .py=Python.File > ftype Python.File Python.File="C:\Python26\python.exe" "%1" %* Depending on how your Python was installed, these may or may not be in place. You can set them with assoc and ftype. > assoc .py=Python.File > ftype Python.File="C:\Python26\python.exe" "%1" %* Also, if .py is included in the PATHEXT environment variable, you can run .py files without the trailing .py. > set PATHEXT=%PATHEXT%;.py > django-admin startproject helloworld
2
4
0
I am trying to run my python scripts in the command-prompt without calling python.exe first. I am specifically doing this in relation to running django-admin.py. I have C:\Python26 and C:\Python26\Scripts in my PATH. However, if I try running django-admin.py by doing: django-admin.py startproject helloworld I get the message: Type 'django-admin.py help' for usage. Now, after some experimentation, I realized the problem is that the secondary arguments to these scripts are not being passed for some reason, since I tried it with a some other python scripts I have. I know I could avoid this problem by simply doing: python C:\Python26\Scripts\django-admin.py startproject helloworld But I know it should be possible to run the first command only and get it to work, because I had it working before. I've looked everywhere, and not many places have been helpful so any idea would be useful for me at this point. Update: The .py file associations were set correctly, and the problem is still occuring.
Issues running python scripts in Command Prompt (Specifically with command line arguments)?
0.379949
0
0
1,347
2,437,167
2010-03-13T03:31:00.000
1
0
0
0
python,scripting,command-prompt
4,603,488
2
false
1
0
I know this is an old thread, but I have searched for a few weeks for this very same problem and found nothing. Today, however, I tried something new: If you are using Windows 7, do not use Command Prompt for scripting purposes. Instead, use the Windows PowerShell located at: All Programs -> Accessories -> Windows PowerShell -> Windows PowerShell. In there you can run the command django-admin.py startproject mysite if you added the correct paths to your environmental paths. BTW, I'm now using Python 2.7 with Django 1.2.4 on Windows 7 Ultimate 32bit.
2
4
0
I am trying to run my python scripts in the command-prompt without calling python.exe first. I am specifically doing this in relation to running django-admin.py. I have C:\Python26 and C:\Python26\Scripts in my PATH. However, if I try running django-admin.py by doing: django-admin.py startproject helloworld I get the message: Type 'django-admin.py help' for usage. Now, after some experimentation, I realized the problem is that the secondary arguments to these scripts are not being passed for some reason, since I tried it with a some other python scripts I have. I know I could avoid this problem by simply doing: python C:\Python26\Scripts\django-admin.py startproject helloworld But I know it should be possible to run the first command only and get it to work, because I had it working before. I've looked everywhere, and not many places have been helpful so any idea would be useful for me at this point. Update: The .py file associations were set correctly, and the problem is still occuring.
Issues running python scripts in Command Prompt (Specifically with command line arguments)?
0.099668
0
0
1,347
2,437,196
2010-03-13T03:46:00.000
2
0
1
0
python,character-codes
2,437,201
3
true
0
0
\v is a vertical tab. It was used in line printers to advance about 6 lines or so. It can be typed in *nix by pressing Ctrl-V Ctrl-K. \f is a formfeed. It was used in line printers to advance to the next page. It can be typed in *nix by pressing Ctrl-V Ctrl-L.
1
1
0
In Python's module named string, there is a line that says whitespace = ' \t\n\r\v\f'. ' ' is a space character. '\t' is a tab character. '\n' is a newline character. '\r' is a carriage-return character. '\v' maps to '\x0b' (11). What does it mean and how might it be typed on a keyboard (any OS)? '\f' maps to '\x0c' (12). What does it mean and how might it be typed on a keyboard (any OS)?
Special Character Meanings Defined
1.2
0
0
327
2,437,582
2010-03-13T07:06:00.000
1
1
0
0
python,ruby
2,437,648
2
false
0
0
$ cat > hello.rb $hello = 'Hello, world!' puts $hello ^D $ irb irb(main):001:0> load 'hello.rb' Hello, world! => true irb(main):002:0> $hello => "Hello, world!" A bit tedious, and local variables won't carry through. May be close enough for your usage? (This is basically like Python's execfile.)
2
2
0
ruby -n is the closest thing I found, but it repeats the whole script. Also it's not available for irb.
Is there a ruby equivalent of "python -i"?
0.099668
0
0
267
2,437,582
2010-03-13T07:06:00.000
1
1
0
0
python,ruby
2,880,523
2
true
0
0
irb -r hello.rb
2
2
0
ruby -n is the closest thing I found, but it repeats the whole script. Also it's not available for irb.
Is there a ruby equivalent of "python -i"?
1.2
0
0
267
2,439,039
2010-03-13T16:22:00.000
1
0
0
0
python,wxwidgets
2,439,208
2
false
0
1
You can embed IE, but I think that's about it. wxWebKit is working on a wx add-on to use WebKit as an embedded browser in wx, but I think it's still a work in progress.
1
0
0
I need to show a webpage (a complex page with script and stuff, no static html) in a frame or something. It's for a desktop application, I'm using python 2.6 + wxPython 2.8.10.1. I need to catch some events too (mostly about changing page). I've found some samples using the webview module in a gtk application, but I couldn't have it works on wx.
how to embed a webpage using wx?
0.099668
0
0
788
2,439,216
2010-03-13T17:17:00.000
1
0
1
0
python
2,439,234
6
false
0
0
Introduce them to enough tools (array slicing and perhaps functional-style recursion, in particular) to accomplish the reversal. Then, let them struggle with trying to figure it out for a while. Take a few different answers and compare them, showing the pros and cons of each way.
1
4
0
I am teaching a course "Introduction to Computer Programming" to the first year math students. One has to assume that this is the first exposure of students to computer programming. Here are the main goals of my teaching: Students should learn and understand the basics of Python. Eventually they need to master sufficiently many Python tools so that they are able to select the right tool for a given problem. At the same time they have to learn basic skills of problem solving by computer programming. My method of teaching is to give for each newly introduced concept a series of problems and teasers that motivate students. For instance, when introducing strings and lists a natural question is the task of string or list reversal. If I ask students to write a code that will check whether a string is a palindrome then I better tell them how to reverse it. For lists, a natural solution myString.reverse() has at least two drawbacks: It does not carry over to strings. Students will see it a magic unless told about methods first. The real question is: How should one introduce the problem of reversing a string in Python?
How to teach beginners reversing a string in Python?
0.033321
0
0
2,254
2,439,520
2010-03-13T18:40:00.000
3
0
1
0
python,wxwidgets,tkinter,py2exe
2,440,302
4
false
0
1
If you're not afraid to learn a new language, consider Tcl/Tk. The reason I mention this is Tcl's superior-to-almost-everything distribution mechanism which makes it really easy to wrap up a single file exe that includes everything you need -- the Tcl/Tk runtime, your program, icons, sound files, etc. inside an embedded virtual filesystem. And the same technique you use for one platform works for all. You don't have to use different tools for different platforms. If that intrigues you, google for starpack (single file that has it all), starkit (platform-independent application) and tclkit (platform-specific runtime). Tcl/Tk isn't everyone's cup of tea, but as a getting-started GUI language it's hard to beat IMO. If it has an Achilles heel is that it has no printing support. It's surprising, though, how many GUIs don't need printing support these days.
2
7
0
I'm a newbie with a little experience writing in BASIC, Python and, of all things, a smidgeon of assembler (as part of a videogame ROM hack). I wanted to create small tool for modifying the hex values at particular points, in a particular file, that would have a GUI interface. What I'm looking for is the ability to create small GUI program, that I can distribute as an EXE (or, at least a standalone directory). I'm not keen on the idea of the .NET languages, because I don't want to force people to download a massive .NET framework package. I currently have Python with IDLE and Boa Constructor set up, and the application runs there. I've tried looking up information on compiling a python app that relies on Wxwidgets, but the search results and the information I've found has been confusing, or just completely incomprehensible. My questions are: Is python a good language to use for this sort of project? If I use Py2Exe, will WxWidgets already be included? Or will my users have to somehow install WxWidgets on their machines? Am I right in thinking at Py2Exe just produces a standalone directory, 'dist', that has the necessary files for the user to just double click and run the application? If the program just relies upon Tkinter for GUI stuff, will that be included in the EXE Py2Exe produces? If so, are their any 'visual' GUI builders / IDEs for Python with only Tkinter? Thankyou for your time, JBMK
As a newbie, where should I go if I want to create a small GUI program?
0.148885
0
0
640
2,439,520
2010-03-13T18:40:00.000
0
0
1
0
python,wxwidgets,tkinter,py2exe
2,440,232
4
false
0
1
Python would fit your needs. wxWidgets and Python are completely different things. I think you mean wxPython, which is a GUI toolkit for Python. I am not sure whether Py2Exe would include this, as I have never used Py2Exe - I build the packages and their dependencies manually. Pretty sure tkinter would be included. I use tkinter a bit and it works well enough.
2
7
0
I'm a newbie with a little experience writing in BASIC, Python and, of all things, a smidgeon of assembler (as part of a videogame ROM hack). I wanted to create small tool for modifying the hex values at particular points, in a particular file, that would have a GUI interface. What I'm looking for is the ability to create small GUI program, that I can distribute as an EXE (or, at least a standalone directory). I'm not keen on the idea of the .NET languages, because I don't want to force people to download a massive .NET framework package. I currently have Python with IDLE and Boa Constructor set up, and the application runs there. I've tried looking up information on compiling a python app that relies on Wxwidgets, but the search results and the information I've found has been confusing, or just completely incomprehensible. My questions are: Is python a good language to use for this sort of project? If I use Py2Exe, will WxWidgets already be included? Or will my users have to somehow install WxWidgets on their machines? Am I right in thinking at Py2Exe just produces a standalone directory, 'dist', that has the necessary files for the user to just double click and run the application? If the program just relies upon Tkinter for GUI stuff, will that be included in the EXE Py2Exe produces? If so, are their any 'visual' GUI builders / IDEs for Python with only Tkinter? Thankyou for your time, JBMK
As a newbie, where should I go if I want to create a small GUI program?
0
0
0
640
2,439,638
2010-03-13T19:09:00.000
1
0
1
0
python
2,439,836
5
false
0
0
I have recently taught a short Python crash course to 1st-3rd year Computer Science students the majority of whom knew only C and C++, and even that not so well. My approach was quite different from what you are suggesting. Disclaimer: The aim of my course was to introduce the language to people who are already familiar with basic ideas of programming, so this might not be appropriate if you are teaching people who have never been exposed to programming at all. First, I did a short introduction to the language with its strengths and weaknesses and showing some simple Python programs that even someone who does not know Python can easily get. Then I did a thorough run through data structures, using the REPL prompt extensively for examples. Sure, at this point they could not write a program, but writing any program (even if just a toy example) without using data structures is really not what Python is about; I would even say that attempting that suggests unpythonic habits to the students. I went in this order: Numbers (int -> float) Sequences (list & tuple -> string -> bytearray) Sets Dictionaries Bools, including auto-casting to bools. Next up was the basic syntax, in the order: Statements (line breaks, etc.) Printing Variables, focusing on the peculiarities of dynamic binding and the major difference between the C concept of variables and its Python counterpart. Conditionals Loops List comprehension Function/method calls, including function chaining, keyword parameters and argument lists. Modules, including importing and dealing with namespaces. Forth was a deep dive into functions. There's a surprising lot to teach about Python functions, including various ways of defining arguments (keywords, lists), multiple returns, docstrings, scoping (a large subject area by itself), and an important but oft-missed part which is using functions as objects, passing them around, using lambdas, etc. Fifth was a more practical overview of files including I/O and encoding issues and exceptions (concept -> catching -> raising). Finally an overview of OO features in Python, including instance variables, method types (instance/class/static), inheritance, method naming (private, mangled, special), etc. For your particular questions: For instance, my predecessor introduced lists before strings. I think the opposite is a better solution. I disagree. Conceptually, a string is just a list that gets a lot of special treatment, so it makes sense to build upon the simpler list concept. If you start with data structures as I did, you also won't have to deal with not being able to use strings in I/O examples. Should function definitions be introduced at the very beginning or after mastering basic structured programming ideas, such as decisions (if) and loops (while)? Definitely after. Calling functions should be taught around the same time as basic structured programming ideas, but defining your own should be postponed. Should sets be introduced before dictionaries? Well, dictionaries are certainly much more used in practice, but if you've introduced sequences, explaining sets (especially to math students) shouldn't take long, and it makes sense to progress from simpler to more complex structures. Is it better to introduce reading and writing files early in the course or should one use input and print for most of the course? Python's IO capabilities are really simple, so it shouldn't matter much, but I'd say these are unnecessary for basic exercises, so you might as well leave them off for the second half of the course. In my view, at each stage the students should be able to solve a non-trivial programming problem using only the tools available at that time. Each new tool should enable a simpler solution to a familiar problem. The incremental approach is obviously very different from my more academic one, but it certainly has its advantages, not least of which is that it keeps people more interested. However, I always disliked the fact that when you're done with learning a subject this way, you are left with the feeling that there might well be an easier solution than what you've learned so far to even the simplest problems, since there always have been during the span of the course.
1
17
0
I am teaching Python to undergraduate math majors. I am interested in the optimal order in which students should be introduced to various Python concepts. In my view, at each stage the students should be able to solve a non-trivial programming problem using only the tools available at that time. Each new tool should enable a simpler solution to a familiar problem. A selection of numerous concepts available in Python is essential in order to keep students focused. They should also motivated and should appreciate each newly mastered tool without too much memorization. Here are some specific questions: For instance, my predecessor introduced lists before strings. I think the opposite is a better solution. Should function definitions be introduced at the very beginning or after mastering basic structured programming ideas, such as decisions (if) and loops (while)? Should sets be introduced before dictionaries? Is it better to introduce reading and writing files early in the course or should one use input and print for most of the course? Any suggestions with explanations are most welcome. Edit: In high school the students were introduced to computers. A few of them learned how to program. Prior to this they had a course, covering word, excel, powerpoint, html, latex, a taste of Mathematica, but no programming. 5 years ago I used Mathematica in this course and the follow-up course uses C and later Java. Now I teach introduction to Python and in the follow-up course my colleague teaches object-oriented programming in Python. Later a student may take special courses on data structures, algorithms, optimization and in some elective courses they learn on their own Mathematica, Matlab and R.
In what order should the Python concepts be explained to absolute beginners?
0.039979
0
0
3,231
2,439,677
2010-03-13T19:21:00.000
1
0
0
0
python,wxpython
2,463,869
1
true
0
1
Your only chance is to write some Custom Menu, which could be bit difficult but doable. So basically instead of using system menu etc, you create windows inside your main frame which look like menu.
1
0
0
I want to know if it's possible to put a frame or a panel over a menubar using wxpython? Thanks in advance!
Is it possible to put a wx.window (frame/panel) over a wx.MenuBar?
1.2
0
0
123
2,439,708
2010-03-13T19:30:00.000
-1
0
0
0
python,wxpython
2,440,868
2
false
0
1
don't think it's doable -- it defaults to the platform's native look
1
1
0
I want to change the wxpython menubar colours. How can I do it?
How can we change a wx.MenuBar background and foreground colour using wxpython?
-0.099668
0
0
1,776
2,439,837
2010-03-13T20:01:00.000
0
0
1
0
python,range
2,439,859
5
false
0
0
numpy.arange might serve your purpose well.
1
1
0
I can print a range of numbers easily using range, but is is possible to print a range with 1 decimal place from -10 to 10? e.g -10.0, -9.9, -9.8 all they way through to +10?
How to print a range with decimal points in Python?
0
0
0
1,691
2,439,987
2010-03-13T20:54:00.000
1
0
1
0
python,internet-explorer,caching,pylons
3,907,139
4
false
0
0
The jQuery library has pretty nice ajax functions, and settings to control them. One of them is is called "cache" and it will automatically append a random number to the query that essentially forces the browser to not cache the page. This can be set along with the parameter "dataType", which can be set to "json" to make the ajax request get json data. I've been using this in my code and haven't had a problem with IE. Hope this helps
1
2
0
I'm have an action /json that returns json from the server. Unfortunately in IE, the browser likes to cache this json. How can I make it so that this action doesn't cache?
Disable browser caching in pylons
0.049958
0
1
1,603
2,440,511
2010-03-13T23:35:00.000
8
1
0
1
python,cpu,temperature
2,440,544
12
false
0
0
If your Linux supports ACPI, reading pseudo-file /proc/acpi/thermal_zone/THM0/temperature (the path may differ, I know it's /proc/acpi/thermal_zone/THRM/temperature in some systems) should do it. But I don't think there's a way that works in every Linux system in the world, so you'll have to be more specific about exactly what Linux you have!-)
1
28
0
How do I retrieve the temperature of my CPU using Python? (Assuming I'm on Linux)
Getting CPU temperature using Python?
1
0
0
57,891
2,440,554
2010-03-13T23:44:00.000
0
0
0
1
python,video,media,gstreamer
31,616,242
3
false
0
0
Why re-invent the wheel? Use: gst-discoverer-1.0 filename or gst-discoverer-0.10 filename Depending on the file type you may want to add " | grep Duration" to avoid the tags which can be lengthy. For the ridding of extraneous tags for video,flac and mp3 files this should do the trick by using grep to exclude them. gst-discoverer-1.0 filename | grep -v Tags | grep -v ID3v2 | grep -v image | grep -v attachment
1
13
0
How do I find the playback time of media with gstreamer?
How do I find the length of media with gstreamer?
0
0
0
6,793
2,440,579
2010-03-13T23:53:00.000
3
0
1
0
python,macos,gcc,distutils,setup.py
2,440,981
2
true
0
0
I'm guessing you've installed 2.6 on 10.5 using the python.org OS X installer. In that case, the flags are accurate and you should not try to change them. The python.org installers are built using the so-called 10.4u SDK and with a deployment target of 10.3, allowing one installer image to work on Mac OS X systems from 10.3.9 up through 10.6 (and possibly beyond). The most recent releases of Python 2.6 have been fixed to ensure that extension module building on OS X forces the C compiler options to match those of the underlying Python so you'll need to make sure you install the 10.4u SDK (or whatever) if necessary from the Xcode package (on the OS X release CD/DVD or downloaded from the Apple Developer Connection website). It will also make sure you are using gcc-4.0, which is also the default on 10.5.
1
2
0
I'm trying to install matplotlib on my mac setup. I find that setup.py has inaccurate flags, in particular the isysroot points to an earlier SDK. Where does setup.py get its info and how can i fix it? I'm on MacOS 10.5.8, XCode 3.1.2 and Python 2.6 (default config was 2.5)
Compiler options wrong with python setup.py
1.2
0
0
1,851
2,441,078
2010-03-14T03:24:00.000
4
0
1
0
python,documentation-generation,python-sphinx,epydoc
21,603,879
3
false
0
0
I recently changed from Python2 to Python3 and found that there was no Epydoc package for Python3. So it seems with Python3 there is a clear focus on using Sphinx as API documentation.
1
29
0
There seems to be a plethora of documentation tools for Python. Another one that I've run across is epydoc. It seems like Sphinx is the de facto standard, because it's used to generate the official Python docs. Can someone please sort out the current state of Python's documentation tools for me?
What is the relationship between docutils and Sphinx?
0.26052
0
0
8,801
2,441,172
2010-03-14T04:24:00.000
2
1
1
0
python,interpreter,embedding
2,441,185
5
false
0
0
Making a frozen binary using a utility like cx_freeze or py2exe is probably the easiest way to do this. That way you only need to distribute the executable. I know that you might prefer not to distribute a binary, but if that is a concern you could always give users the option to download the source and run from an interpreter.
2
8
0
I'm looking for a way to ship the Python interpreter with my application (also written in Python), so that it doesn't need to have Python installed on the machine. I searched Google and found a bunch of results about how to embed the Python interpreter in applications written in various languages, but nothing for applications written in Python itself... I don't need to "hide" my code or make a binary like cx_freeze does, I just don't want my users to have to install Python to use my app, that's all.
Embed Python interpreter in a Python application
0.07983
0
0
3,296
2,441,172
2010-03-14T04:24:00.000
2
1
1
0
python,interpreter,embedding
2,441,182
5
false
0
0
You need some sort of executable in order to start Python. May as well be the one your app has been frozen into. The alternative is to copy the executable, library, and pieces of the stdlib that you need into a private directory and invoke that against your app.
2
8
0
I'm looking for a way to ship the Python interpreter with my application (also written in Python), so that it doesn't need to have Python installed on the machine. I searched Google and found a bunch of results about how to embed the Python interpreter in applications written in various languages, but nothing for applications written in Python itself... I don't need to "hide" my code or make a binary like cx_freeze does, I just don't want my users to have to install Python to use my app, that's all.
Embed Python interpreter in a Python application
0.07983
0
0
3,296
2,444,165
2010-03-14T22:56:00.000
4
0
1
0
python,distribution
2,444,202
2
false
0
0
A zipfile (with just the .pyc or .pyo files in it, ideally) would suffice, especially if you're distributing code supporting a specific X.Y version of Python (any Z in X.Y.Z will do, i.e., if you support Python 2.6, that will work in 2.6.1, 2.6.2, and so on). Just make the zipfile part of the PYTHONPATH, just as if it was a directory, and you're good to go. If you support many different Python versions (in the X.Y sense) you can make a zipfile per version, it's still pretty simple.
2
3
0
I am writing a console application in python that will consist of a handful of modules, each with a couple hundred lines of code. For development it would be nice to modularize the program, but for distribution I like the idea of being able to post the program as a single python script. Are there any good scripts out there for flattening multiple python modules? I know that eventually I should brave the complicated mess that is setuptools, dpkg, etc... but I'm not ready to invest that effort yet.
Good way to flatten a multiple file python program for distribution?
0.379949
0
0
340
2,444,165
2010-03-14T22:56:00.000
0
0
1
0
python,distribution
2,596,282
2
true
0
0
No code to do this seems to exist.
2
3
0
I am writing a console application in python that will consist of a handful of modules, each with a couple hundred lines of code. For development it would be nice to modularize the program, but for distribution I like the idea of being able to post the program as a single python script. Are there any good scripts out there for flattening multiple python modules? I know that eventually I should brave the complicated mess that is setuptools, dpkg, etc... but I'm not ready to invest that effort yet.
Good way to flatten a multiple file python program for distribution?
1.2
0
0
340
2,444,897
2010-03-15T03:19:00.000
1
0
1
0
python,com
2,444,939
2
false
0
0
The CLSID is at least supposed not to change. Naturally a program can do a lot many stupid things breaking regulations. But: AS the CLSID is how the class is loaded, a changed CLSID would mean the USING program of a class would also have to use the changed CLSID. Su, yous assumption is right - if the same program in the same version is installed on two computers, it is safe to assume the CLSID does not change. This is even supposed t obe so between versions.... but if the library Foo 1.0 is only used by one program, the programmer may get away with a changed CLSID. It is not supposed to change, though.
2
0
0
I am using comtypes to generate wrappers for a certain com library. I am having certain issues with a few things, that are not being generated properly. I can get around this by doing the missing work, manually. However can i depend on the fact that CLSID's will not change? Lets say: I install a program with the com library Foo 1.0, now i install the exact same version of that program on another PC, will the CLSID's of the interfaces change? This might be a terribly dumb question.
Can a CLSID be different for the same program installed on two different machines?
0.099668
0
0
563
2,444,897
2010-03-15T03:19:00.000
1
0
1
0
python,com
2,444,964
2
true
0
0
Disclaimer: Done a lot of COM, but never with python. The UUID for a COM interface is part of the definition of the interface. It should be the same on every machine, and for all time. Also, in ATL COM land, classes have CLSIDs, interfaces have IIDs. They both have UUIDs (or possibly GUIDs). Not sure about python.
2
0
0
I am using comtypes to generate wrappers for a certain com library. I am having certain issues with a few things, that are not being generated properly. I can get around this by doing the missing work, manually. However can i depend on the fact that CLSID's will not change? Lets say: I install a program with the com library Foo 1.0, now i install the exact same version of that program on another PC, will the CLSID's of the interfaces change? This might be a terribly dumb question.
Can a CLSID be different for the same program installed on two different machines?
1.2
0
0
563
2,445,193
2010-03-15T05:04:00.000
7
0
1
0
python
2,445,239
5
false
0
0
Python is dynamically typed: all variables can refer to an object of any type. id and name can be anything, but the actual objects are of types like int and str. 0 is a literal that is parsed to make an int object, and 'John' a literal that makes a str object. Many object types do not have literals and are returned by a callable (like frozenset—there's no way to make a literal frozenset, you must call frozenset.) Consequently, there is no such thing as declaration of variables, since you aren't defining anything about the variable. id = 0 and name = 'John' are just assignment. increase returns an int because that's what you return in it; nothing in Python forces it not to be any other object. first and second are only ints if you make them so. Objects, to a certain extent, share a common interface. You can use the same operators and functions on them all, and if they support that particular operation, it works. It is a common, recommended technique to use different types that behave similarly interchangably; this is called duck typing. For example, if something takes a file object you can instead pass a cStringIO.StringIO object, which supports the same method as a file (like read and write) but is a completely different type. This is sort of like Java interfaces, but does not require any formal usage, you just define the appropriate methods.
3
6
0
Sorry if this is quite noobish to you, but I'm just starting out to learn Python after learning C++ & Java, and I am wondering how in the world I could just declare variables like id = 0 and name = 'John' without any int's or string's in front! I figured out that perhaps it's because there are no ''s in a number, but how would Python figure that out in something like def increase(first, second) instead of something like int increase(int first, int second) in C++?!
How does Python differentiate between the different data types?
1
0
0
1,782
2,445,193
2010-03-15T05:04:00.000
13
0
1
0
python
2,445,233
5
true
0
0
The literal objects you mention carry (pointers to;-) their own types with them of course, so when a name's bound to that object the problem of type doesn't arise -- the object always has a type, the name doesn't -- just delegates that to the object it's bound to. There's no "figuring out" in def increase(first, second): -- name increase gets bound to a function object, names first and second are recorded as parameters-names and will get bound (quite possibly to objects of different types at various points) as increase gets called. So say the body is return first + second -- a call to increase('foo', 'bar') will then happily return 'foobar' (delegating the addition to the objects, which in this case are strings), and maybe later a call to increase(23, 45) will just as happily return 68 -- again by delegating the addition to the objects bound to those names at the point of call, which in this case are ints. And if you call with incompatible types you'll get an exception as the delegated addition operation can't make sense of the situation -- no big deal!
3
6
0
Sorry if this is quite noobish to you, but I'm just starting out to learn Python after learning C++ & Java, and I am wondering how in the world I could just declare variables like id = 0 and name = 'John' without any int's or string's in front! I figured out that perhaps it's because there are no ''s in a number, but how would Python figure that out in something like def increase(first, second) instead of something like int increase(int first, int second) in C++?!
How does Python differentiate between the different data types?
1.2
0
0
1,782
2,445,193
2010-03-15T05:04:00.000
4
0
1
0
python
2,445,220
5
false
0
0
When it comes to assigning literal values to variables, the type of the literal value can be inferred at the time of lexical analysis. For example, anything matching the regular expression (-)?[1-9][0-9]* can be inferred to be an integer literal. If you want to convert it to a float, there needs to be an explicit cast. Similarly, a string literal is any sequence of characters enclosed in single or double quotes. In a method call, the parameters are not type-checked. You only need to pass in the correct number of them to be able to call the method. So long as the body of the method does not cause any errors with respect to the arguments, you can call the same method with lots of different types of arguments.
3
6
0
Sorry if this is quite noobish to you, but I'm just starting out to learn Python after learning C++ & Java, and I am wondering how in the world I could just declare variables like id = 0 and name = 'John' without any int's or string's in front! I figured out that perhaps it's because there are no ''s in a number, but how would Python figure that out in something like def increase(first, second) instead of something like int increase(int first, int second) in C++?!
How does Python differentiate between the different data types?
0.158649
0
0
1,782
2,445,761
2010-03-15T08:07:00.000
4
0
0
0
python,mysql,database,django,django-south
2,445,802
3
true
1
0
Yes. I think it is not too late. I've moved to south in a middle of a project and I am happy with that choice. I think it is a big help for deployment. The initialization of the south app can be done at any moment.
1
5
0
I already started a project, and the models are all synced and everything.
Django migrations--is it possible to use South in the middle of the project?
1.2
0
0
561
2,447,118
2010-03-15T12:45:00.000
1
0
1
0
java,python
2,495,504
13
false
1
0
Try to find algorithms that you understand well and see how they are implemented in python standard libraries. Persist. :)
4
34
0
I've been writing Java for the last couple of years , and now I've started to write in python (in addition). The problem is that when I look at my Python code it looks like someone tried to hammer Java code into a python format , and it comes out crappy because - well , python ain't Java. Any tips on how to escape this pattern of "Writing Java in Python"? Thanks!
Programming in Python vs. programming in Java
0.015383
0
0
7,368
2,447,118
2010-03-15T12:45:00.000
0
0
1
0
java,python
2,447,141
13
false
1
0
Learn a few other languages. It will help you make the difference between algorithms (the structure of processing, unchanged between languages) and the local syntaxic features of the language. Then you can "write Foo in Bar" for any combination of languages "Foo" and "Bar".
4
34
0
I've been writing Java for the last couple of years , and now I've started to write in python (in addition). The problem is that when I look at my Python code it looks like someone tried to hammer Java code into a python format , and it comes out crappy because - well , python ain't Java. Any tips on how to escape this pattern of "Writing Java in Python"? Thanks!
Programming in Python vs. programming in Java
0
0
0
7,368
2,447,118
2010-03-15T12:45:00.000
0
0
1
0
java,python
2,495,445
13
false
1
0
Eat Python, Sleep Python and Drink Python. That is the only way........
4
34
0
I've been writing Java for the last couple of years , and now I've started to write in python (in addition). The problem is that when I look at my Python code it looks like someone tried to hammer Java code into a python format , and it comes out crappy because - well , python ain't Java. Any tips on how to escape this pattern of "Writing Java in Python"? Thanks!
Programming in Python vs. programming in Java
0
0
0
7,368
2,447,118
2010-03-15T12:45:00.000
3
0
1
0
java,python
2,448,287
13
false
1
0
Definitely not a panacea but I think you should try some code golf in Python. Obviously nobody should write "golfed" code IRL, but finding the most terse way to express something really forces you to exploit the built in functionality of the language.
4
34
0
I've been writing Java for the last couple of years , and now I've started to write in python (in addition). The problem is that when I look at my Python code it looks like someone tried to hammer Java code into a python format , and it comes out crappy because - well , python ain't Java. Any tips on how to escape this pattern of "Writing Java in Python"? Thanks!
Programming in Python vs. programming in Java
0.046121
0
0
7,368
2,447,143
2010-03-15T12:48:00.000
19
0
1
0
python,flush
2,447,205
5
false
0
0
NB: close() and flush() won't ensure that the data is actually secure on the disk. It just ensures that the OS has the data == that it isn't buffered inside the process. You can try sync or fsync to get the data written to the disk.
1
44
0
In Python, and in general - does a close() operation on a file object imply a flush() operation?
does close() imply flush() in Python?
1
0
0
16,987
2,448,035
2010-03-15T14:58:00.000
0
0
0
0
python,django,pickle
2,448,188
2
false
1
0
You can overload the serialization methods. But it would be simpler to put the id and class in a tuple or dict and pickle that.
2
4
0
My app uses a "per-user session" to allow multiple sessions from the same user to share state. It operates very similarly to the django session by pickling objects. I need to pickle a complex object that refers to django model objects. The standard pickling process stores a denormalized object in the pickle. So if the object changes on the database between pickling and unpickling, the model is now out of date. (I know this is true with in-memory objects too, but the pickling is a convenient time to address it.) Clearly it would be cleaner to store this complex in the database, but it's not practical. The code for it is necessarily changing rapidly as the project evolves. Having to update the database schema every time the object's data model changes would slow the project down a lot. So what I'd like is a way to not pickle the full django model object. Instead just store its class and id, and re-fetch the contents from the database on load. Can I specify a custom pickle method for this class? I'm happy to write a wrapper class around the django model to handle the lazy fetching from db, if there's a way to do the pickling.
How to customize pickle for django model objects
0
0
0
2,714
2,448,035
2010-03-15T14:58:00.000
1
0
0
0
python,django,pickle
2,448,369
2
true
1
0
It's unclear what your goal is. "But if I just store the id and class in a tuple then I'm necessarily going back to the database every time I use any of the django objects. I'd like to be able to keep the ones I'm using in memory over the course of a page request." This doesn't make sense, since a view function is a page request and you have local variables in your view function that keep your objects around until you're finished. Further, Django's ORM bas a cache. Finally, the Django-supplied session is the usual place for "in-memory objects" between requests. You shouldn't need to pickle anything.
2
4
0
My app uses a "per-user session" to allow multiple sessions from the same user to share state. It operates very similarly to the django session by pickling objects. I need to pickle a complex object that refers to django model objects. The standard pickling process stores a denormalized object in the pickle. So if the object changes on the database between pickling and unpickling, the model is now out of date. (I know this is true with in-memory objects too, but the pickling is a convenient time to address it.) Clearly it would be cleaner to store this complex in the database, but it's not practical. The code for it is necessarily changing rapidly as the project evolves. Having to update the database schema every time the object's data model changes would slow the project down a lot. So what I'd like is a way to not pickle the full django model object. Instead just store its class and id, and re-fetch the contents from the database on load. Can I specify a custom pickle method for this class? I'm happy to write a wrapper class around the django model to handle the lazy fetching from db, if there's a way to do the pickling.
How to customize pickle for django model objects
1.2
0
0
2,714
2,448,984
2010-03-15T17:08:00.000
0
1
1
1
python,linux,multithreading,mutex
2,449,391
5
false
0
0
Write code using immutable objects. Write objects that implement the Singleton Pattern. Use a stable Distributed messaging technology such as IPC, webservices, or XML-RPC. I would take a look at Twisted. They got plenty of solutions for such task. I wouldn't use threads in Python esp with regards to the GIL, I would look at using Processes as working applications and use a comms technology as described above for intercommunications. Your singleton class could then appear in one of these applications and interfaced via comms technology of choice. Not a fast solution with all the interfacing, but if done correctly should be stable.
2
7
0
Our server cluster consists of 20 machines, each with 10 pids of 5 threads. We'd like some way to prevent any two threads, in any pid, on any machine, from modifying the same object at the same time. Our code's written in Python and runs on Linux, if that helps narrow things down. Also, it's a pretty rare case that two such threads want to do this, so we'd prefer something that optimizes the "only one thread needs this object" case to be really fast, even if it means that the "one thread has locked this object and another one needs it" case isn't great. What are some of the best practices?
What are some good ways to do intermachine locking?
0
0
0
2,492
2,448,984
2010-03-15T17:08:00.000
1
1
1
1
python,linux,multithreading,mutex
2,466,954
5
false
0
0
if you can get the complete infrastructure for a distributed lock manager then go ahead and use that. But that infrastructure is not easy to setup! But here is a practical solution: -designate the node with the lowest ip address as the the master node (that means if the node with lowest ip address hangs, a new node with lowest ip address will become new master) -let all nodes contact the master node to get the lock on the object. -let the master node use native lock semantics to get the lock. this will simplify things unless you need complete clustering infrastructure and DLM to do the job.
2
7
0
Our server cluster consists of 20 machines, each with 10 pids of 5 threads. We'd like some way to prevent any two threads, in any pid, on any machine, from modifying the same object at the same time. Our code's written in Python and runs on Linux, if that helps narrow things down. Also, it's a pretty rare case that two such threads want to do this, so we'd prefer something that optimizes the "only one thread needs this object" case to be really fast, even if it means that the "one thread has locked this object and another one needs it" case isn't great. What are some of the best practices?
What are some good ways to do intermachine locking?
0.039979
0
0
2,492
2,449,115
2010-03-15T17:28:00.000
0
0
0
0
python,django,python-imaging-library
2,449,251
1
true
1
0
Ah, if i only open the orginal image once and create the thumbnail after resizing then the problem is solved
1
0
0
I have been using pil for the first time today. And I wanted to resize an image assuming it was larger than 800x600 and also create a thumbnail. I could do either of these tasks separately but not together in one method (I am doing a custom save method in django admin). This returns a "cannot identify image file" error message. The error is on the line "image = Image.open(self.photo)" after "#if image is size is greatet than 800 x 600 then resize image." I thought this may be because the image is already open, but if i remove the line I still get issues. So I thought I could try closing after creating a thumbnail and then reopening. But I couldn't find a close method....
Python Image Library, Close method
1.2
0
0
773
2,451,682
2010-03-16T02:03:00.000
10
0
0
0
python,eclipse,import
2,452,084
8
false
0
0
It sounds like MySQLdb is somewhere on your sys.path, but not on your Eclipse project's PYTHONPATH; in other words, Eclipse thinks you're going to get an import error at runtime because you haven't fully configured it. Google seems to say that you can alter this setting in Window->Preferences->Preferences->PyDev->Python Interpreter to include the path to your MySQLdb module. For some help figuring out where MySQLdb might be living on your system: Open an interactive interpreter, import MySQLdb If that succeeds, you can get a hint from: print MySQLdb.__file__; it may be the __init__ file in the package that you need to point the path at.
2
11
0
When I write import MySQLdb in Eclipse using the PyDev plugin, I get an unresolved import. However, the program runs without error. I can add an annotation to get the error to go away, but what is the right way to handle this? How can I help Eclipse know that MySQLdb is there?
How do I handle an UnresolvedImport Eclipse (Python)
1
0
0
16,362
2,451,682
2010-03-16T02:03:00.000
10
0
0
0
python,eclipse,import
12,980,991
8
false
0
0
cdleary above provided the reason two years ago, but this may be easier. Basically, one reinstalls the interpreter. Select Window - > Preferences -> PyDev -> Interpreter - Python Select the python interpreter in the upper pane Click on Remove Click on Auto Config Agree to everything. This works on Fedora 17 using the Eclipse 4.2.0 that came with the package management.
2
11
0
When I write import MySQLdb in Eclipse using the PyDev plugin, I get an unresolved import. However, the program runs without error. I can add an annotation to get the error to go away, but what is the right way to handle this? How can I help Eclipse know that MySQLdb is there?
How do I handle an UnresolvedImport Eclipse (Python)
1
0
0
16,362
2,452,488
2010-03-16T06:24:00.000
3
0
1
1
python,security,filesystems,sandbox
2,452,503
3
false
0
0
You are probably best to use a virtual machine like VirtualBox or VMware (perhaps even creating one per user/session). That will allow you some control over other resources such as memory and network as well as disk The only python that I know of that has such features built in is the one on Google App Engine. That may be a workable alternative for you too.
1
4
0
I have a web service to which users upload python scripts that are run on a server. Those scripts process files that are on the server and I want them to be able to see only a certain hierarchy of the server's filesystem (best: a temporary folder on which I copy the files I want processed and the scripts). The server will ultimately be a linux based one but if a solution is also possible on Windows it would be nice to know how. What I though of is creating a user with restricted access to folders of the FS - ultimately only the folder containing the scripts and files - and launch the python interpreter using this user. Can someone give me a better alternative? as relying only on this makes me feel insecure, I would like a real sandboxing or virtual FS feature where I could run safely untrusted code.
faking a filesystem / virtual filesystem
0.197375
0
0
1,877
2,454,494
2010-03-16T13:06:00.000
0
0
0
0
python,header,urllib2,setcookie
39,896,162
3
false
0
0
set-cookie is different though. From RFC 6265: Origin servers SHOULD NOT fold multiple Set-Cookie header fields into a single header field. The usual mechanism for folding HTTP headers fields (i.e., as defined in [RFC2616]) might change the semantics of the Set-Cookie header field because the %x2C (",") character is used by Set-Cookie in a way that conflicts with such folding. In theory then, this looks like a bug.
1
3
0
I am using urllib2 to interact with a website that sends back multiple Set-Cookie headers. However the response header dictionary only contains one - seems the duplicate keys are overriding each other. Is there a way to access duplicate headers with urllib2?
urllib2 multiple Set-Cookie headers in response
0
0
1
3,778
2,454,576
2010-03-16T13:19:00.000
5
1
1
0
python,import,global-variables,module
2,454,624
2
false
0
0
When you import a module B (like import B), every line in B will be interpreted. I assume this is what you mean when you say you want to run it. To reference members in B's namespace, you can get them like: B.something_defined_in_B. If you wish to use sys explicitly in C, you will need to import it within C as well.
1
0
0
I have a module "B", I want to run it from a script "C", and I want to call global variables in "B", as they were in the "C" root. Another problem is if I imported sys in "B" when I run "C" it doesn't see sys # NameError: global name 'sys' is not defined # What shall I do?
How do you run python scripts from other script and have their root in my root?
0.462117
0
0
4,158
2,455,018
2010-03-16T14:13:00.000
0
0
0
0
python,django,panel,admin
2,455,815
3
false
1
0
The automatically generated administration area created by Django is for data maintenance. It provides forms to edit data in your models. If it doesn't "handle this feature", then it sounds like your "configuration panel" (configuration panel should let me choose some basic options like highlighting some news, setting a showcase banner, and so on) does not have any data model. If you define a model with basic options like highlighting some news, setting a showcase banner, and so on then the Django admin will update rows in the model. You can then use the model data to configure your application. If -- for some reason -- you don't want to put this in the database, then there will never be an automatically generated administration area created by Django.
1
2
0
I would like to create a configuration panel for the homepage of the web-app I'm designing with Django. This configuration panel should let me choose some basic options like highlighting some news, setting a showcase banner, and so on. Basically I don't need an app with different rows, but just a panel page with some configuration options. The automatically generated administration area created by Django doesn't seem to handle this feature as far as I can see, so I'm asking you for some directions. Any hint is highly appreciated. Thank you in advance. Matteo
How to create a custom admin configuration panel in Django?
0
0
0
4,970
2,455,062
2010-03-16T14:20:00.000
19
1
1
0
python,emacs,spell-checking,docstring
2,455,436
1
true
0
0
I recommend you to try flyspell-mode. You could use something like: (add-hook 'python-mode-hook 'flyspell-prog-mode) in your Emacs configuration.
1
11
0
I'd like to run a spell checker on the docstrings of my Python code, if possible from within emacs. I've found the ispell-check-comments setting which can be used to spell check only comments in code, but I was not able to target only the docstrings which are a fairly python-specific thing.
How to spell check python docstring with emacs?
1.2
0
0
1,226
2,456,226
2010-03-16T16:35:00.000
1
1
1
0
python,unit-testing,automation
2,456,703
2
true
0
0
I do this type of thing for testing Unix user creation and home directory copies. The Zip suggestion is a good one. I personally keep two directory structures -- one is a source and one becomes the test structure. I just sync the source to the destination via shutil.copytree as part of the test setup. That makes it easy to change the test structure on the fly (and not have to unzip).
1
2
0
I'm looking for a way to create a tree of test files to unit test a packaging tool. Basically, I want to create some common file system structures -- directories, nested directories, symlinks within the selected tree, symlinks outside the tree, &c. Ideally I want to do this with as little boilerplate as possible. Of course, I could hand-write the set of files I want to see, but I'm thinking that somebody has to have automated this for a test suite somewhere. Any suggestions?
Using Python, what's the best way to create a set of files on disk for testing?
1.2
0
0
149
2,456,926
2010-03-16T18:11:00.000
0
0
0
0
python,pylons
2,457,303
1
false
1
1
I'm assuming that "I can only get the first value" means you've got a series of checkboxes with the same value for the 'name' attribute within your form? Now, if that's the case and you're wanting a list of boolean values based on whether or not the boxes are checked or not, you'll need to do two things: First, when you define your form elements using form encode on your checkbox, set it up such that a missing value on a checkbox element returns 'False.' This way, as the browser won't send a value over unless a checkbox is "on", you validation coerces the missing value to False. class Registration(formencode.Schema): box = formencode.validators.StringBoolean(if_missing=False) Next, assuming you want a list returned, you'll not be able to name all of your elements the same. Pylons supports a nested structure, though. Look at formencode.variabledecode.NestedVariables. In short, you'll need to define a NestedVariables instance as one of your class attributes and your form 'name' attributes will need to change in order to contain explicit indexes. Edit.. here's a complete example I did real quick: import logging import pprint import formencode from pylons import request, response, session, tmpl_context as c, url from pylons.controllers.util import abort, redirect from pylons.decorators import validate from testproj.lib.base import BaseController, render log = logging.getLogger(__name__) class CheckList(formencode.Schema): box = formencode.validators.StringBoolean(if_missing=False) hidden = formencode.validators.String() class EnclosingForm(formencode.Schema): pre_validators = [formencode.NestedVariables()] boxes = formencode.ForEach(CheckList()) class MyformController(BaseController): def index(self): schema = EnclosingForm() v = schema.to_python(dict(request.params)) # Return a rendered template #return render('/myform.mako') # or, return a response response.content_type = 'text/plain' return pprint.pformat(v) And then the query string? boxes-0.box=true&boxes-0.hidden=hidden&boxes-1.box=true& boxes-1.hidden=hidden&boxes-2.hidden=hidden And lastly, the response: {'boxes': [{'box': True, 'hidden': u'hidden'}, {'box': True, 'hidden': u'hidden'}, {'box': False, 'hidden': u'hidden'}]} HTH
1
1
0
I have been trying to add some check boxes in a pylons mako. However I don't know how to get their values in the controller. It seems that it can only get the first value of the check boxes. I tried using form encode but i got several errors. Is there an easier way to do this? Thanks
Checkboxes with pylons
0
0
0
1,306
2,457,367
2010-03-16T19:16:00.000
3
0
1
0
python,memory,performance,substring
2,457,480
4
false
0
0
As with most garbage collected languages, strings are created as often as needed, which is very often. The reason for this is because tracking substrings as described would make garbage collection more difficult. What is the actual algorithm you are trying to implement. It might be possible to give you advice for ways to get better results if we knew a bit more about it. As for an alternative, what is it you really need to do? Could you use a different way of looking at the issue, such as just keeping an integer index into the string? Could you use a array.array('u')?
3
4
0
I've got the entire contents of a text file (at least a few KB) in string myStr. Will the following code create a copy of the string (less the first character) in memory? myStr = myStr[1:] I'm hoping it just refers to a different location in the same internal buffer. If not, is there a more efficient way to do this? Thanks! Note: I'm using Python 2.5.
How efficient is Python substring extraction?
0.148885
0
0
2,172
2,457,367
2010-03-16T19:16:00.000
4
0
1
0
python,memory,performance,substring
2,457,449
4
true
0
0
At least in 2.6, slices of strings are always new allocations; string_slice() calls PyString_FromStringAndSize(). It doesn't reuse memory--which is a little odd, since with invariant strings, it should be a relatively easy thing to do. Short of the buffer API (which you probably don't want), there isn't a more efficient way to do this operation.
3
4
0
I've got the entire contents of a text file (at least a few KB) in string myStr. Will the following code create a copy of the string (less the first character) in memory? myStr = myStr[1:] I'm hoping it just refers to a different location in the same internal buffer. If not, is there a more efficient way to do this? Thanks! Note: I'm using Python 2.5.
How efficient is Python substring extraction?
1.2
0
0
2,172
2,457,367
2010-03-16T19:16:00.000
1
0
1
0
python,memory,performance,substring
2,458,894
4
false
0
0
Depending on what you are doing, itertools.islice may be a suitable memory-efficient solution (should one become necessary).
3
4
0
I've got the entire contents of a text file (at least a few KB) in string myStr. Will the following code create a copy of the string (less the first character) in memory? myStr = myStr[1:] I'm hoping it just refers to a different location in the same internal buffer. If not, is there a more efficient way to do this? Thanks! Note: I'm using Python 2.5.
How efficient is Python substring extraction?
0.049958
0
0
2,172
2,458,296
2010-03-16T21:28:00.000
1
0
0
1
python
2,458,335
5
false
0
0
If you're worried about writes, you can have a set of servers that dispatch the tasks (may be stripe the servers to equalize load) and have each server write bulk checkpoints to the DB (this way, you will not have so many write queries). You still have to write to be able to recover if scheduling server dies, of course. In addition, if you don't have a clustered index on timestamp, you will avoid having a hot-spot at the end of the table.
2
17
0
We have hundreds of thousands of tasks that need to be run at a variety of arbitrary intervals, some every hour, some every day, and so on. The tasks are resource intensive and need to be distributed across many machines. Right now tasks are stored in a database with an "execute at this time" timestamp. To find tasks that need to be executed, we query the database for jobs that are due to be executed, then update the timestamps when the task is complete. Naturally this leads to a substantial write load on the database. As far as I can tell, we are looking for something to release tasks into a queue at a set interval. (Workers could then request tasks from that queue.) What is the best way to schedule recurring tasks at scale? For what it's worth we're largely using Python, although we have no problems using components (RabbitMQ?) written in other languages. UPDATE: Right now we have about 350,000 tasks that run every half hour or so, with some variation. 350,000 tasks * 48 times per day is 16,800,000 tasks executed per day. UPDATE 2: There are no dependencies. The tasks do not have to be executed in order and do not rely on previous results.
How to schedule hundreds of thousands of tasks?
0.039979
0
0
2,429
2,458,296
2010-03-16T21:28:00.000
1
0
0
1
python
2,459,571
5
false
0
0
350,000 tasks * 48 times per day is 16,800,000 tasks executed per day. To schedule the jobs, you don't need a database. Databases are for things that are updated. The only update visible here is a change to the schedule to add, remove or reschedule a job. Cron does this in a totally scalable fashion with a single flat file. Read the entire flat file into memory, start spawning jobs. Periodically, check the fstat to see if the file changed. Or, even better, wait for a HUP signal and use that to reread the file. Use kill -HUP to signal the scheduler to reread the file. It's unclear what you're updating the database for. If the database is used to determine future schedule based on job completion, then a single database is a Very Dad Idea. If you're using the database to do some analysis of job history, then you have a simple data warehouse. Record completion information (start time, end time, exit status, all that stuff) in a simple flat log file. Process the flat log files to create a fact table and dimension updates. When someone has the urge to do some analysis, load relevant portions of the flat log files into a datamart so they can do queries and counts and averages and the like. Do not directly record 17,000,000 rows per day into a relational database. No one wants all that data. They want summaries: counts and averages.
2
17
0
We have hundreds of thousands of tasks that need to be run at a variety of arbitrary intervals, some every hour, some every day, and so on. The tasks are resource intensive and need to be distributed across many machines. Right now tasks are stored in a database with an "execute at this time" timestamp. To find tasks that need to be executed, we query the database for jobs that are due to be executed, then update the timestamps when the task is complete. Naturally this leads to a substantial write load on the database. As far as I can tell, we are looking for something to release tasks into a queue at a set interval. (Workers could then request tasks from that queue.) What is the best way to schedule recurring tasks at scale? For what it's worth we're largely using Python, although we have no problems using components (RabbitMQ?) written in other languages. UPDATE: Right now we have about 350,000 tasks that run every half hour or so, with some variation. 350,000 tasks * 48 times per day is 16,800,000 tasks executed per day. UPDATE 2: There are no dependencies. The tasks do not have to be executed in order and do not rely on previous results.
How to schedule hundreds of thousands of tasks?
0.039979
0
0
2,429
2,458,355
2010-03-16T21:39:00.000
6
0
0
0
python,django,web-applications
2,458,468
2
false
1
0
In Django, I'd suggest having a property on the User (or Profile) model that calculates a user's reputation on-demand. Then, cache the reputation with your caching framework and/or store to the database for fast retrieval. This way, in addition to having the records of what impacts reputation, you can change your reputation criteria at will.
2
8
0
I'm thinking of adding a reputation system to my Django web application; the site is already being used so I'm trying to be careful about my choices. Reputation is generated in all actions that contribute to the site, similar to Stackoverflow's system. I know there are literally millions of ways of implementing this, and this is why I feel quite lost. Two alternatives I am not sure about are: Keep track of reasons why reputation was incremented Ignore reasons in order to reduce complexity of the site and overhead Would be happy with a few pointers, and directions. Would be very much appreciated!
Giving users a "reputation system" - Should I...?
1
0
0
550
2,458,355
2010-03-16T21:39:00.000
4
0
0
0
python,django,web-applications
2,458,375
2
false
1
0
keep track of the reasons, IMHO. It surely wouldn't be that complex, and you don't need to store a huge amount of information, just a datetime, point value, command, target, and originator. If the data gets to be too much after some time dump the DB to a backup medium and clear the history.
2
8
0
I'm thinking of adding a reputation system to my Django web application; the site is already being used so I'm trying to be careful about my choices. Reputation is generated in all actions that contribute to the site, similar to Stackoverflow's system. I know there are literally millions of ways of implementing this, and this is why I feel quite lost. Two alternatives I am not sure about are: Keep track of reasons why reputation was incremented Ignore reasons in order to reduce complexity of the site and overhead Would be happy with a few pointers, and directions. Would be very much appreciated!
Giving users a "reputation system" - Should I...?
0.379949
0
0
550
2,458,624
2010-03-16T22:30:00.000
2
0
0
1
python,linux,file-io,flush
2,458,697
3
true
0
0
It's somewhat filesystem dependent, but in some filesystems, if you delete a file before (all of) it is allocated, the IO to write the blocks will never happen. This might also be true if you truncate it so that the part which is still being written is chopped off. Not sure that you can really abort a write if you want to still access the data. Also the kinds of filesystems that support this (e.g. xfs, ext4) are not normally used on USB sticks. If you want to flush data to the disc, use fdatasync(). Merely flushing your IO library's buffer into the OS one will not achieve any physical flushing.
2
3
0
Is there a way to abort a python write operation in such a way that the OS doesn't feel it's necessary to flush the unwritten data to the disc? I'm writing data to a USB device, typically many megabytes. I'm using 4096 bytes as my block size on the write, but it appears that Linux caches up a bunch of data early on, and write it out to the USB device slowly. If at some point during the write, my user decides to cancel, I want the app to just stop writing immediately. I can see that there's a delay between when the data stops flowing from the application, and the USB activity light stops blinking. Several seconds, up to about 10 seconds typically. I find that the app is holding in the close() method, I'm assuming, waiting for the OS to finish writing the buffered data. I call flush() after every write, but that doesn't appear to have any impact on the delay. I've scoured the python docs for an answer but have found nothing.
Abort a slow flush to disk after write?
1.2
0
0
683
2,458,624
2010-03-16T22:30:00.000
1
0
0
1
python,linux,file-io,flush
2,458,871
3
false
0
0
When you abort the write operation, trying doing file.truncate(0); before closing it.
2
3
0
Is there a way to abort a python write operation in such a way that the OS doesn't feel it's necessary to flush the unwritten data to the disc? I'm writing data to a USB device, typically many megabytes. I'm using 4096 bytes as my block size on the write, but it appears that Linux caches up a bunch of data early on, and write it out to the USB device slowly. If at some point during the write, my user decides to cancel, I want the app to just stop writing immediately. I can see that there's a delay between when the data stops flowing from the application, and the USB activity light stops blinking. Several seconds, up to about 10 seconds typically. I find that the app is holding in the close() method, I'm assuming, waiting for the OS to finish writing the buffered data. I call flush() after every write, but that doesn't appear to have any impact on the delay. I've scoured the python docs for an answer but have found nothing.
Abort a slow flush to disk after write?
0.066568
0
0
683
2,459,300
2010-03-17T01:13:00.000
11
0
1
0
python,import
2,459,384
4
true
0
0
Best practice is to import every module that defines identifiers you need, and use those identifiers as qualified by the module's name; I recommend using from only when what you're importing is a module from within a package. The question has often been discussed on SO. Importing a module, say moda, from many modules (say modb, modc, modd, ...) that need one or more of the identifiers moda defines, does not slow you down: moda's bytecode is loaded (and possibly build from its sources, if needed) only once, the first time moda is imported anywhere, then all other imports of the module use a fast path involving a cache (a dict mapping module names to module objects that is accessible as sys.modules in case of need... if you first import sys, of course!-).
4
3
0
I have a file, myfile.py, which imports Class1 from file.py and file.py contains imports to different classes in file2.py, file3.py, file4.py. In my myfile.py, can I access these classes or do I need to again import file2.py, file3.py, etc.? Does Python automatically add all the imports included in the file I imported, and can I use them automatically?
Python importing
1.2
0
0
15,516
2,459,300
2010-03-17T01:13:00.000
1
0
1
0
python,import
2,459,311
4
false
0
0
Python doesn't automatically introduce anything into the namespace of myfile.py, but you can access everything that is in the namespaces of all the other modules. That is to say, if in file1.py you did from file2 import SomeClass and in myfile.py you did import file1, then you can access it within myfile as file1.SomeClass. If in file1.py you did import file2 and in myfile.py you did import file1, then you can access the class from within myfile as file1.file2.SomeClass. (These aren't generally the best ways to do it, especially not the second example.) This is easily tested.
4
3
0
I have a file, myfile.py, which imports Class1 from file.py and file.py contains imports to different classes in file2.py, file3.py, file4.py. In my myfile.py, can I access these classes or do I need to again import file2.py, file3.py, etc.? Does Python automatically add all the imports included in the file I imported, and can I use them automatically?
Python importing
0.049958
0
0
15,516
2,459,300
2010-03-17T01:13:00.000
0
0
1
0
python,import
2,459,322
4
false
0
0
In the myfile module, you can either do from file import ClassFromFile2 or from file2 import ClassFromFile2 to access ClassFromFile2, assuming that the class is also imported in file. This technique is often used to simplify the API a bit. For example, a db.py module might import various things from the modules mysqldb, sqlalchemy and some other helpers. Than, everything can be accessed via the db module.
4
3
0
I have a file, myfile.py, which imports Class1 from file.py and file.py contains imports to different classes in file2.py, file3.py, file4.py. In my myfile.py, can I access these classes or do I need to again import file2.py, file3.py, etc.? Does Python automatically add all the imports included in the file I imported, and can I use them automatically?
Python importing
0
0
0
15,516
2,459,300
2010-03-17T01:13:00.000
0
0
1
0
python,import
2,459,332
4
false
0
0
If you are using wildcard import, yes, wildcard import actually is the way of creating new aliases in your current namespace for contents of the imported module. If not, you need to use the namespace of the module you have imported as usual.
4
3
0
I have a file, myfile.py, which imports Class1 from file.py and file.py contains imports to different classes in file2.py, file3.py, file4.py. In my myfile.py, can I access these classes or do I need to again import file2.py, file3.py, etc.? Does Python automatically add all the imports included in the file I imported, and can I use them automatically?
Python importing
0
0
0
15,516
2,459,549
2010-03-17T02:26:00.000
1
0
0
0
python,zope,web2py,zodb,grok
9,985,357
3
false
1
0
Zope and the ZODB have been used with big applications, but I'd still consider linking Zope with MySQL or something like that for serious large-scale applications. Even though Zope has had a lot of development cycles, it is usually used with another database engine for good reason. As far as I know, the argument applies doubly for web2py.
2
3
0
I am planning to make some big project (1 000 000 users, approximately 500 request pre second - in hot time). For performance I'm going to use no relational dbms (each request could cost lot of instructions in relational dbms like mysql) - so i can't use DAL. My question is: how web2py is working with a big traffic, is it work concurrently? I'm consider to use web2py or Gork - Zope, How is working zodb(Z Object Database) with a lot of data? Is there some comparison with object-relational postgresql? Could you advice me please.
web2py or grok (zope) on a big portal,
0.066568
1
0
1,388
2,459,549
2010-03-17T02:26:00.000
7
0
0
0
python,zope,web2py,zodb,grok
2,459,620
3
false
1
0
First, don't assume that a data abstraction layer will have unacceptable performance, until you actually see it in practice. It is pretty easy to switch to RAW sql if and when you run into a problem. Second, most users who worry about there server technology handling a million users never finish their applications. Pick whatever technology you think will enable you to build the best application in the shortest time. Any technology can be scaled, at the very least, through clustering.
2
3
0
I am planning to make some big project (1 000 000 users, approximately 500 request pre second - in hot time). For performance I'm going to use no relational dbms (each request could cost lot of instructions in relational dbms like mysql) - so i can't use DAL. My question is: how web2py is working with a big traffic, is it work concurrently? I'm consider to use web2py or Gork - Zope, How is working zodb(Z Object Database) with a lot of data? Is there some comparison with object-relational postgresql? Could you advice me please.
web2py or grok (zope) on a big portal,
1
1
0
1,388
2,459,636
2010-03-17T02:54:00.000
0
1
1
0
python-3.x,relative-path
5,054,020
1
false
0
0
You are trying to run the test files directly, then you can't have relative imports. Change them to be absolute imports, and it will solve the problem.
1
0
0
I am currently working with converting Pycrypto over to Python 3.X Whilst I seem to have the cryptography side working the same cannot be said for the tests provided with the module :( I have used the tests under Python 2.64 and all works fine. I then ran '2to3' over the tests to generate new files in 3.X format. There are several references to the following: from .common import make_block_tests Whenever I run the tests I get: ValueError: Attempted relative import in non-package If someone would point me towards a way to fix this it would be much appreciated :) Cheers Grail
Python 3 relative path conversion issue
0
0
0
215
2,459,739
2010-03-17T03:29:00.000
1
0
0
0
python,cluster-analysis
2,460,285
4
false
0
0
Yeah I think there isn't a good implementation to what I need. I have some crazy requirements, like distance caching etc. So i think i will just write my own lib and release it as GPLv3 soon.
1
9
1
I am interested to perform kmeans clustering on a list of words with the distance measure being Leveshtein. 1) I know there are a lot of frameworks out there, including scipy and orange that has a kmeans implementation. However they all require some sort of vector as the data which doesn't really fit me. 2) I need a good clustering implementation. I looked at python-clustering and realize that it doesn't a) return the sum of all the distance to each centroid, and b) it doesn't have any sort of iteration limit or cut off which ensures the quality of the clustering. python-clustering and the clustering algorithm on daniweb doesn't really work for me. Can someone find me a good lib? Google hasn't been my friend
Python KMeans clustering words
0.049958
0
0
1,947
2,460,177
2010-03-17T06:02:00.000
9
0
1
0
python,algorithm,edit,distance
24,172,422
10
false
0
0
Here is my version for Levenshtein distance def edit_distance(s1, s2): m=len(s1)+1 n=len(s2)+1 tbl = {} for i in range(m): tbl[i,0]=i for j in range(n): tbl[0,j]=j for i in range(1, m): for j in range(1, n): cost = 0 if s1[i-1] == s2[j-1] else 1 tbl[i,j] = min(tbl[i, j-1]+1, tbl[i-1, j]+1, tbl[i-1, j-1]+cost) return tbl[i,j] print(edit_distance("Helloworld", "HalloWorld"))
1
57
0
I'm programming a spellcheck program in Python. I have a list of valid words (the dictionary) and I need to output a list of words from this dictionary that have an edit distance of 2 from a given invalid word. I know I need to start by generating a list with an edit distance of one from the invalid word(and then run that again on all the generated words). I have three methods, inserts(...), deletions(...) and changes(...) that should output a list of words with an edit distance of 1, where inserts outputs all valid words with one more letter than the given word, deletions outputs all valid words with one less letter, and changes outputs all valid words with one different letter. I've checked a bunch of places but I can't seem to find an algorithm that describes this process. All the ideas I've come up with involve looping through the dictionary list multiple times, which would be extremely time consuming. If anyone could offer some insight, I'd be extremely grateful.
Edit Distance in Python
1
0
0
109,493
2,460,401
2010-03-17T07:04:00.000
2
0
1
0
python,matplotlib,tkinter,break,python-idle
31,151,803
4
false
0
0
I had same issue in Canopy Python Editor, and I was able to interrupt python session with CTRL+. ("dot" button). Hope that helps, or they probably do things in a similar ways
3
11
0
I have a python script that uses plt.show() as it's last instruction. When it runs, IDLE just hangs after the last instruction. I get the image but I don't get the prompt back. On other scripts I typically use ctrl-c to break the program (sometimes doesn't work immediately) but how do I get the prompt back with the plt.show()? Ctrl-c doesn't work... Are there other ways to stop the program? This is IDLE on Windows, if it makes any difference.
How to stop Python program execution in IDLE
0.099668
0
0
54,617
2,460,401
2010-03-17T07:04:00.000
7
0
1
0
python,matplotlib,tkinter,break,python-idle
2,460,438
4
true
0
0
I have seen this problem with IDLE and matplotlib when using them on Windows. I don't know the exact cause, but Ctrl-c a couple times has typically worked for me. If that doesn't work for you, you can use the normal interpreter instead of write your plot directly to a file instead of the screen. This is one of those (plentiful) times when IDLE doesn't behave like a normal Python script or interpreter session. Because of this, I usually avoid IDLE.
3
11
0
I have a python script that uses plt.show() as it's last instruction. When it runs, IDLE just hangs after the last instruction. I get the image but I don't get the prompt back. On other scripts I typically use ctrl-c to break the program (sometimes doesn't work immediately) but how do I get the prompt back with the plt.show()? Ctrl-c doesn't work... Are there other ways to stop the program? This is IDLE on Windows, if it makes any difference.
How to stop Python program execution in IDLE
1.2
0
0
54,617
2,460,401
2010-03-17T07:04:00.000
7
0
1
0
python,matplotlib,tkinter,break,python-idle
20,615,556
4
false
0
0
Ctrl+F6 (Restart shell) or Shell->Restart Shell
3
11
0
I have a python script that uses plt.show() as it's last instruction. When it runs, IDLE just hangs after the last instruction. I get the image but I don't get the prompt back. On other scripts I typically use ctrl-c to break the program (sometimes doesn't work immediately) but how do I get the prompt back with the plt.show()? Ctrl-c doesn't work... Are there other ways to stop the program? This is IDLE on Windows, if it makes any difference.
How to stop Python program execution in IDLE
1
0
0
54,617
2,460,491
2010-03-17T07:28:00.000
1
0
0
0
python,mysql,database,datetime,date
2,460,546
3
false
0
0
Solved. I just did this: datetime.datetime.now() ...insert that into the column.
1
5
0
I am using Python MySQLDB, and I want to insert this into DATETIME field in Mysql . How do I do that with cursor.execute?
In Python, if I have a unix timestamp, how do I insert that into a MySQL datetime field?
0.066568
1
0
9,981
2,461,364
2010-03-17T10:15:00.000
3
0
0
0
python,django,redirect,search-form
2,461,426
1
true
1
0
Search queries should probably be GETs, rather than POSTs, because they are not changing anything - they are simply passing parameters to get certain information. POST should be reserved for forms that actually change things in the database, or result in a specific action (eg submitting an email). To reply to your comment, hiding parameters from URLs is not particularly good practice, but if you really think you need to, this is an instance where it's OK not to redirect after the form submission - again, because you're not affecting anything with the POST.
1
0
0
After processing form from POST I should redirect, to prevent user from hitting back. However, I am using form to determine search query on a database, so I need to either pass params to the redirected site or the result of a search. Or maybe there is some other good practice, how to solve this problem? Maybe in this situation I am allowed not to redirect (nothing happens, if user performs search again).
django: search forms and redirect
1.2
0
0
726
2,461,964
2010-03-17T11:59:00.000
2
1
0
0
python,cgi,backgroundworker
2,462,349
1
false
1
0
well, short answer: you can't. medium answer: CGI sucks. long answer: CGI works by running your script and returning whatever your script prints to the browser. If your script is still running, the browser will be waiting. If your script launches a background job and returns data to the browser, then the background job can't notify the CGI script because it is already done. You must choose an alternate solution. Save the results of the background job to a file, database, or some other persistent storage, and make the user request that data, using another link in your page, which runs a different code that retrieves the saved results and display them. Another way is to use AJAX techniques in the browser. Write javascript code to do the request to the data in the background. So the browser can still be responsive with other page elements while the script is running.
1
1
0
I have a python CGI which runs some script in the background and shows the stdout in the html page. I run the script when the user clicks some button in the page. My problem is when the script starts running the page becomes busy and the user can't use the other client side features in the page. What I want is: The script should run in background when the user clicks the button and should notify the CGI when run is complete. Then the CGI show should the stdout of the script run. How can this be done?
Running a python script in background from a CGI
0.379949
0
0
1,221
2,464,442
2010-03-17T17:32:00.000
0
1
0
0
python,zope
2,466,236
2
true
1
0
Maybe you could create a new template including (use-macro) just the macros you want to access from python and then use z3c.pt.pagetemplate.PageTemplateFile() to render it? Actually, it might be possible (and certainly easier) to use chameleon.zpt.template.PageTemplate('<div tal:use-macro="<your-macro-here>" />'), but I've never did this myself.
2
1
0
One of our page templates is made up of a bunch of macros. These items are a bunch of html tables. Now, I want a couple of these tables in a Python script to create a PDF. Is there a way call a macro from a Python script and get back the HTML that is produced? If so, can you explain? Thanks Eric
Call macro from Python script?
1.2
0
0
334
2,464,442
2010-03-17T17:32:00.000
0
1
0
0
python,zope
2,464,507
2
false
1
0
I'd probably use urllib.urlopen(url), pull the data from the page back to python and use BeautifulSoup to pull the table(s) out of the HTML... And then render that to PDF with XHTML2PDF (pisa.ho). There might be a simpler way but for me, this would be the least stressful approach.
2
1
0
One of our page templates is made up of a bunch of macros. These items are a bunch of html tables. Now, I want a couple of these tables in a Python script to create a PDF. Is there a way call a macro from a Python script and get back the HTML that is produced? If so, can you explain? Thanks Eric
Call macro from Python script?
0
0
0
334
2,464,568
2010-03-17T17:50:00.000
0
0
1
0
python
2,464,634
6
false
0
0
Basically this method tells you if the first parameter is a subclass of the second. So naturally, both your parameters need to be classes. It appears from your call, that you have called issubclass without any parameters, which confuses the interpreter. Calling issubclass is like asking the interpreter: "Hey! is this class a subclass of this other class?". However, since you have not provided two classes, you have essentially asked the interpretter: "Hey! I'm not going to show you anything, but tell me if this it's a subclass". This confuses the interpreter and that's why you get this error.
1
7
0
I have zero idea as to why I'm getting this error.
Can someone explain what exactly this error means,TypeError: issubclass() arg 1 must be a class
0
0
0
30,197
2,464,704
2010-03-17T18:09:00.000
1
0
1
1
python,subprocess,watchdog
2,464,752
2
false
0
0
I've done this same thing to process web statistics using a semaphore. Essentially, as processes are created, the semaphore is incremented. When they exit, it's decremented. The creation process is blocked when the semaphore blocks. This actually fires off threads, which run external processes down execution path a bit. Here's an example. thread_sem = threading.Semaphore(int(cfg.maxthreads)) for k,v in log_data.items(): thread_list.append(ProcessorThread(int(k), v, thread_sem)) thread_list[-1].start() And then in the constructor for ProcessorThread, I do this: def __init__(self, siteid, data, lock_object): threading.Thread.__init__(self) self.setDaemon(False) self.lock_object = lock_object self.data = data self.siteid = siteid self.lock_object.acquire() When the thread finishes it's task (whether successfully or not), the lock_object is released which allows for another process to begin. HTH
1
2
0
I need it to open 10 processes, and each time one of them finishes I want to wait few seconds and start another one. It seems pretty simple, but somehow I can't get it to work.
How to implement a master/watchdog script in python?
0.099668
0
0
1,275
2,465,056
2010-03-17T18:59:00.000
2
0
0
1
python,google-app-engine,artificial-intelligence
2,471,015
3
false
1
0
If the game is turn based then it would probably be best to avoid the Cron task and just update the NPCs every time the player moves. I'm not sure how big of a map you are planning on but you may consider even having the player object find the NPCs that are close to it and call their AI routine. That way NPCs that are out of range of a player wouldn't move at all which may save on resources. Not sure if that matter though.
3
1
0
I am currently in the planning stages of a game for google app engine, but cannot wrap my head around how I am going to handle AI. I intend to have persistant NPCs that will move about the map, but short of writing a program that generates the same XML requests I use to control player actions, than run it on another server I am stuck on how to do it. I have looked at the Task Queue feature, but due to long running processes not being an option on the App engine, I am a little stuck. I intend to run multiple server instances with 200+ persistant NPC entities that I will need to update. Most action is slowly roaming around based on player movements/concentrations, and attacking close range players...(you can probably guess the type of game im developing)
Artificial Intelligence in online game using Google App Engine
0.132549
0
0
1,026
2,465,056
2010-03-17T18:59:00.000
2
0
0
1
python,google-app-engine,artificial-intelligence
2,471,126
3
false
1
0
Bear in mind that you can also break up your updates into multiple requests (internally): do a bit of work, redirect to the same handler but different state; do more work; etc. (I'm failing somehow to comment on Peter Recore's answer, which is where this really belongs.) I see that the free service only allows 100k task queue calls/day, so 1 task/NPC would probably use up your resources way too fast. Cron job to do some work/create task queues to update NPCs in appropriately-sized groups? Anyway, just some thoughts; good luck.
3
1
0
I am currently in the planning stages of a game for google app engine, but cannot wrap my head around how I am going to handle AI. I intend to have persistant NPCs that will move about the map, but short of writing a program that generates the same XML requests I use to control player actions, than run it on another server I am stuck on how to do it. I have looked at the Task Queue feature, but due to long running processes not being an option on the App engine, I am a little stuck. I intend to run multiple server instances with 200+ persistant NPC entities that I will need to update. Most action is slowly roaming around based on player movements/concentrations, and attacking close range players...(you can probably guess the type of game im developing)
Artificial Intelligence in online game using Google App Engine
0.132549
0
0
1,026
2,465,056
2010-03-17T18:59:00.000
3
0
0
1
python,google-app-engine,artificial-intelligence
2,465,142
3
true
1
0
Will your game be turn based or real time? Either way, I think you have 2 options to look into. One is to use the Cron feature so you can schedule NPC updates at regular intervals, the other is to stick a "update NPCs" task into the Task Queue every time a human player moves.
3
1
0
I am currently in the planning stages of a game for google app engine, but cannot wrap my head around how I am going to handle AI. I intend to have persistant NPCs that will move about the map, but short of writing a program that generates the same XML requests I use to control player actions, than run it on another server I am stuck on how to do it. I have looked at the Task Queue feature, but due to long running processes not being an option on the App engine, I am a little stuck. I intend to run multiple server instances with 200+ persistant NPC entities that I will need to update. Most action is slowly roaming around based on player movements/concentrations, and attacking close range players...(you can probably guess the type of game im developing)
Artificial Intelligence in online game using Google App Engine
1.2
0
0
1,026
2,465,719
2010-03-17T20:40:00.000
0
0
1
0
python,regex
2,465,817
4
false
0
0
Some regular expressions match a finite number of input strings, but many (most?) match an infinite number of input strings. It's kind of like asking 'given the python language grammar, generate all possible python programs'. You probably could write a program to list them all in sequence if you tried (though it would take infinite time to run), but are you sure you want to? Why would you want to? I'm pretty sure the regular expression engine in the standard library does not expose a way to generate the output you want. You'd have to get lower level access to the internal data structures, or implement some DFA engine thing-a-ma-bob yourself.
1
2
0
I'm trying to use a regex as an input, and from there generate all the possible values that the regex would match. So, for example, if the regex is "three-letter words starting with a, and ending in c," then the code would generate a list with the values [aac, abc, acc, adc, a1c....]. Is there an easy way to do this? I'm using python.
Generating a list of values a regex COULD match in Python
0
0
0
2,614
2,467,609
2010-03-18T04:55:00.000
-6
0
0
1
python,linux
2,467,717
6
false
0
0
No reason to use python. Avoid writing a shell script in Python and go with something like bash or an equivalent.
2
32
0
How would I download files (video) with Python using wget and save them locally? There will be a bunch of files, so how do I know that one file is downloaded so as to automatically start downloding another one? Thanks.
Using wget via Python
-1
0
1
92,663
2,467,609
2010-03-18T04:55:00.000
9
0
0
1
python,linux
2,467,646
6
false
0
0
No reason to use os.system. Avoid writing a shell script in Python and go with something like urllib.urlretrieve or an equivalent. Edit... to answer the second part of your question, you can set up a thread pool using the standard library Queue class. Since you're doing a lot of downloading, the GIL shouldn't be a problem. Generate a list of the URLs you wish to download and feed them to your work queue. It will handle pushing requests to worker threads. I'm waiting for a database update to complete, so I put this together real quick. #!/usr/bin/python import sys import threading import urllib from Queue import Queue import logging class Downloader(threading.Thread): def __init__(self, queue): super(Downloader, self).__init__() self.queue = queue def run(self): while True: download_url, save_as = queue.get() # sentinal if not download_url: return try: urllib.urlretrieve(download_url, filename=save_as) except Exception, e: logging.warn("error downloading %s: %s" % (download_url, e)) if __name__ == '__main__': queue = Queue() threads = [] for i in xrange(5): threads.append(Downloader(queue)) threads[-1].start() for line in sys.stdin: url = line.strip() filename = url.split('/')[-1] print "Download %s as %s" % (url, filename) queue.put((url, filename)) # if we get here, stdin has gotten the ^D print "Finishing current downloads" for i in xrange(5): queue.put((None, None))
2
32
0
How would I download files (video) with Python using wget and save them locally? There will be a bunch of files, so how do I know that one file is downloaded so as to automatically start downloding another one? Thanks.
Using wget via Python
1
0
1
92,663
2,467,807
2010-03-18T06:03:00.000
0
1
0
0
c++,python,c
2,468,907
3
false
1
0
I don't think you should use a compiled language (at least not c++) for web programming. I thought about doing this once too but remember that for any change you'll have to compile etc. Facebook uses php and it's hip hop application changes php into c++. Maybe you should take a look at that. Of course c++ (or any compiled language) will be faster than an interpreted language, but you also have to take in account the development time of the web site/app. Hope this helps :)
1
2
0
Can C/C++ be choice of keeping all your logic (business/domain) for web application? Why? I've two resources (cousins) having knowledge on C/C++ and me also good in C/C++, Python, HTML, CSS and JavaScript. We like to utilize our free time to work on our some good ideas we developed together. The ideas require knowledge of web application development. And I'm the only one who has it. Is there a way they developed the core in C/C++ and I do the rest of scripting for front-end development? Thanks.
C/C++ for Core Logic Development of a Web Application?
0
0
0
390
2,469,031
2010-03-18T10:31:00.000
7
0
0
0
python,random,open-source,mersenne-twister
2,469,142
2
false
0
0
Mersenne Twister is an implementation that is used by standard python library. You can see it in random.py file in your python distribution. On my system (Ubuntu 9.10) it is in /usr/lib/python2.6, on Windows it should be in C:\Python26\Lib
1
4
1
Is there any good open-source implementation of Mersenne Twister and other good random number generators in Python available? I would like to use in for teaching math and comp sci majors? I am also looking for the corresponding theoretical support. Edit: Source code of Mersenne Twister is readily available in various languages such as C (random.py) or pseudocode (Wikipedia) but I could not find one in Python.
Open-source implementation of Mersenne Twister in Python?
1
0
0
5,857