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
674,229
2009-03-23T16:58:00.000
9
0
1
0
python,indexing,list
674,268
10
false
0
0
To add to Devin's response: This is an old debate between special return values versus exceptions. Many programming gurus prefer an exception because on an exception, I get to see the whole stacktrace and immediate infer what is wrong.
5
26
0
Why does list.index throw an exception, instead of using an arbitrary value (for example, -1)? What's the idea behind this? To me it looks cleaner to deal with special values, rather than exceptions. EDIT: I didn't realize -1 is a potentially valid value. Nevertheless, why not something else? How about a value of None?
Python list.index throws exception when index not found
1
0
0
22,838
674,229
2009-03-23T16:58:00.000
1
0
1
0
python,indexing,list
674,281
10
false
0
0
I agree with Devin Jeanpierre, and would add that dealing with special values may look good in small example cases but (with a few notable exceptions, e.g. NaN in FPUs and Null in SQL) it doesn't scale nearly as well. The only time it works is where: You've typically got lots of nested homogeneous processing (e.g. math or SQL) You don't care about distinguishing error types You don't care where the error occurred The operations are pure functions, with no side effects. Failure can be given a reasonable meaning at the higher level (e.g. "No rows matched")
5
26
0
Why does list.index throw an exception, instead of using an arbitrary value (for example, -1)? What's the idea behind this? To me it looks cleaner to deal with special values, rather than exceptions. EDIT: I didn't realize -1 is a potentially valid value. Nevertheless, why not something else? How about a value of None?
Python list.index throws exception when index not found
0.019997
0
0
22,838
674,764
2009-03-23T18:57:00.000
0
0
1
0
python,string,find
48,610,988
9
false
0
0
if x is a string and you search for y which also a string their is two cases : case 1: y is exist in x so x.find(y) = the index (the position) of the y in x . case 2: y is not exist so x.find (y) = -1 this mean y is not found in x.
1
63
0
I am trying to find some examples but no luck. Does anyone know of some examples on the net? I would like to know what it returns when it can't find, and how to specify from start to end, which I guess is going to be 0, -1.
Examples for string find in Python
0
0
0
376,942
675,442
2009-03-23T22:17:00.000
99
0
1
0
python,docstring
675,452
19
false
0
0
The only cure I know for this is a good editor. Sorry.
5
537
0
Is there a mechanism to comment out large blocks of Python code? Right now, the only ways I can see of commenting out code are to either start every line with a #, or to enclose the code in triple quotes: """. The problem with these is that inserting # before every line is cumbersome and """ makes the string I want to use as a comment show up in generated documentation. After reading all comments, the answer seems to be "No".
How to comment out a block of code in Python
1
0
0
1,947,381
675,442
2009-03-23T22:17:00.000
36
0
1
0
python,docstring
15,196,667
19
false
0
0
In JetBrains PyCharm on Mac use Command + / to comment/uncomment selected block of code. On Windows, use CTRL + /.
5
537
0
Is there a mechanism to comment out large blocks of Python code? Right now, the only ways I can see of commenting out code are to either start every line with a #, or to enclose the code in triple quotes: """. The problem with these is that inserting # before every line is cumbersome and """ makes the string I want to use as a comment show up in generated documentation. After reading all comments, the answer seems to be "No".
How to comment out a block of code in Python
1
0
0
1,947,381
675,442
2009-03-23T22:17:00.000
1
0
1
0
python,docstring
8,910,010
19
false
0
0
On Eric4 there is an easy way: select a block, type Ctrl+M to comment the whole block or Ctrl+alt+M to uncomment.
5
537
0
Is there a mechanism to comment out large blocks of Python code? Right now, the only ways I can see of commenting out code are to either start every line with a #, or to enclose the code in triple quotes: """. The problem with these is that inserting # before every line is cumbersome and """ makes the string I want to use as a comment show up in generated documentation. After reading all comments, the answer seems to be "No".
How to comment out a block of code in Python
0.010526
0
0
1,947,381
675,442
2009-03-23T22:17:00.000
1
0
1
0
python,docstring
8,934,599
19
false
0
0
Another editor-based solution: text "rectangles" in Emacs. Highlight the code you want to comment out, then C-x-r-t # To un-comment the code: highlight, then C-x-r-k I use this all-day, every day. (Assigned to hot-keys, of course.) This and powerful regex search/replace is the reason I tolerate Emacs's other "eccentricities".
5
537
0
Is there a mechanism to comment out large blocks of Python code? Right now, the only ways I can see of commenting out code are to either start every line with a #, or to enclose the code in triple quotes: """. The problem with these is that inserting # before every line is cumbersome and """ makes the string I want to use as a comment show up in generated documentation. After reading all comments, the answer seems to be "No".
How to comment out a block of code in Python
0.010526
0
0
1,947,381
675,442
2009-03-23T22:17:00.000
1
0
1
0
python,docstring
676,446
19
false
0
0
Triple quotes are OK to me. You can use ''' foo ''' for docstrings and """ bar """ for comments or vice-versa to make the code more readable.
5
537
0
Is there a mechanism to comment out large blocks of Python code? Right now, the only ways I can see of commenting out code are to either start every line with a #, or to enclose the code in triple quotes: """. The problem with these is that inserting # before every line is cumbersome and """ makes the string I want to use as a comment show up in generated documentation. After reading all comments, the answer seems to be "No".
How to comment out a block of code in Python
0.010526
0
0
1,947,381
676,460
2009-03-24T07:44:00.000
1
0
0
1
python,google-app-engine,web-crawler
677,133
4
false
1
0
App Engine code only runs in response to HTTP requests, so you can't run a persistent crawler in the background. With the upcoming release of scheduled tasks, you could write a crawler that uses that functionality, but it would be less than ideal.
2
4
0
Is it impossible to run a web crawler on GAE along side with my app considering the I am running the free startup version?
Web crawlers and Google App Engine Hosted applications
0.049958
0
0
3,097
676,460
2009-03-24T07:44:00.000
0
0
0
1
python,google-app-engine,web-crawler
677,320
4
false
1
0
It's possible. But that's not really an application for appengine just as Arachnid wrote. If you manage to get it working I'll doubt you'll stay in the qotas for free accounts.
2
4
0
Is it impossible to run a web crawler on GAE along side with my app considering the I am running the free startup version?
Web crawlers and Google App Engine Hosted applications
0
0
0
3,097
677,028
2009-03-24T11:34:00.000
2
0
0
0
python,sqlite,notifications
677,042
8
false
0
0
Just open a socket between the two processes and have the editor tell all the players about the update.
5
15
0
Let's say I have two or more processes dealing with an SQLite database - a "player" process and many "editor" processes. The "player" process reads the database and updates a view - in my case it would be a waveform being mixed to the soundcard depending on events stored in the database. An "editor" process is any editor for that database: it changes the database constantly. Now I want the player to reflect the editing changes quickly. I know that SQLite supplies hooks to trace database changes within the same process, but there seems to be little info on how to do this with multiple processes. I could poll the database constantly, compare records and trigger events, but that seems to be quite inefficient, especially when the database grows to a large size. I am thinking about using a log table and triggers, but I wonder if there is a simpler method.
How do I notify a process of an SQLite database change done in a different process?
0.049958
1
0
15,631
677,028
2009-03-24T11:34:00.000
2
0
0
0
python,sqlite,notifications
677,215
8
false
0
0
I think in that case, I would make a process to manage the database read/writes. Each editor that want to make some modifications to the database makes a call to this proccess, be it through IPC or network, or whatever method. This process can then notify the player of a change in the database. The player, when he wants to retrieve some data should make a request of the data it wants to the process managing the database. (Or the db process tells it what it needs, when it notifies of a change, so no request from the player needed) Doing this will have the advantage of having only one process accessing the SQLite DB, so no locking or concurrency issues on the database.
5
15
0
Let's say I have two or more processes dealing with an SQLite database - a "player" process and many "editor" processes. The "player" process reads the database and updates a view - in my case it would be a waveform being mixed to the soundcard depending on events stored in the database. An "editor" process is any editor for that database: it changes the database constantly. Now I want the player to reflect the editing changes quickly. I know that SQLite supplies hooks to trace database changes within the same process, but there seems to be little info on how to do this with multiple processes. I could poll the database constantly, compare records and trigger events, but that seems to be quite inefficient, especially when the database grows to a large size. I am thinking about using a log table and triggers, but I wonder if there is a simpler method.
How do I notify a process of an SQLite database change done in a different process?
0.049958
1
0
15,631
677,028
2009-03-24T11:34:00.000
2
0
0
0
python,sqlite,notifications
677,087
8
false
0
0
If it's on the same machine, the simplest way would be to have named pipe, "player" with blocking read() and "editors" putting a token in pipe whenever they modify DB.
5
15
0
Let's say I have two or more processes dealing with an SQLite database - a "player" process and many "editor" processes. The "player" process reads the database and updates a view - in my case it would be a waveform being mixed to the soundcard depending on events stored in the database. An "editor" process is any editor for that database: it changes the database constantly. Now I want the player to reflect the editing changes quickly. I know that SQLite supplies hooks to trace database changes within the same process, but there seems to be little info on how to do this with multiple processes. I could poll the database constantly, compare records and trigger events, but that seems to be quite inefficient, especially when the database grows to a large size. I am thinking about using a log table and triggers, but I wonder if there is a simpler method.
How do I notify a process of an SQLite database change done in a different process?
0.049958
1
0
15,631
677,028
2009-03-24T11:34:00.000
4
0
0
0
python,sqlite,notifications
677,085
8
true
0
0
A relational database is not your best first choice for this. Why? You want all of your editors to pass changes to your player. Your player is -- effectively -- a server for all those editors. Your player needs multiple open connections. It must listen to all those connections for changes. It must display those changes. If the changes are really large, you can move to a hybrid solution where the editors persist the changes and notify the player. Either way, the editors must notify they player that they have a change. It's much, much simpler than the player trying to discover changes in a database. A better design is a server which accepts messages from the editors, persists them, and notifies the player. This server is neither editor nor player, but merely a broker that assures that all the messages are handled. It accepts connections from editors and players. It manages the database. There are two implementations. Server IS the player. Server is separate from the player. The design of server doesn't change -- only the protocol. When server is the player, then server calls the player objects directly. When server is separate from the player, then the server writes to the player's socket. When the player is part of the server, player objects are invoked directly when a message is received from an editor. When the player is separate, a small reader collects the messages from a socket and calls the player objects. The player connects to the server and then waits for a stream of information. This can either be input from the editors or references to data that the server persisted in the database. If your message traffic is small enough so that network latency is not a problem, editor sends all the data to the server/player. If message traffic is too large, then the editor writes to a database and sends a message with just a database FK to the server/player. Please clarify "If the editor crashes while notifying, the player is permanently messed up" in your question. This sounds like a poor design for the player service. It can't be "permanently messed up" unless it's not getting state from the various editors. If it's getting state from the editors (but attempting to mirror that state, for example) then you should consider a design where the player simply gets state from the editor and cannot get "permanently messed up".
5
15
0
Let's say I have two or more processes dealing with an SQLite database - a "player" process and many "editor" processes. The "player" process reads the database and updates a view - in my case it would be a waveform being mixed to the soundcard depending on events stored in the database. An "editor" process is any editor for that database: it changes the database constantly. Now I want the player to reflect the editing changes quickly. I know that SQLite supplies hooks to trace database changes within the same process, but there seems to be little info on how to do this with multiple processes. I could poll the database constantly, compare records and trigger events, but that seems to be quite inefficient, especially when the database grows to a large size. I am thinking about using a log table and triggers, but I wonder if there is a simpler method.
How do I notify a process of an SQLite database change done in a different process?
1.2
1
0
15,631
677,028
2009-03-24T11:34:00.000
1
0
0
0
python,sqlite,notifications
677,169
8
false
0
0
How many editor processes (why processes?), and how often do you expect updates? This doesn't sound like a good design, especially not considering sqlite really isn't too happy about multiple concurrent accesses to the database. If multiple processes makes sense and you want persistence, it would probably be smarter to have the editors notify your player via sockets, pipes, shared memory or the like and then have the player (aka server process) do the persisting.
5
15
0
Let's say I have two or more processes dealing with an SQLite database - a "player" process and many "editor" processes. The "player" process reads the database and updates a view - in my case it would be a waveform being mixed to the soundcard depending on events stored in the database. An "editor" process is any editor for that database: it changes the database constantly. Now I want the player to reflect the editing changes quickly. I know that SQLite supplies hooks to trace database changes within the same process, but there seems to be little info on how to do this with multiple processes. I could poll the database constantly, compare records and trigger events, but that seems to be quite inefficient, especially when the database grows to a large size. I am thinking about using a log table and triggers, but I wonder if there is a simpler method.
How do I notify a process of an SQLite database change done in a different process?
0.024995
1
0
15,631
677,641
2009-03-24T14:28:00.000
5
1
1
0
python,linux,gstreamer
677,681
2
true
0
0
tee will block if either output blocks, so it's probably your bottleneck. I suggest to write the stream that takes longer to encode to disk and encode from there.
2
4
0
I'm trying to use gstreamer 0.10 from Python to simultaneously display a v4l2 video source and record it to xvid-in-avi. Over a long period of time the computer would be fast enough to do this but if another program uses the disk it drops frames. That's bad enough, but on playback there are bursts of movement in the video where frames were dropped instead of displaying the frames we were able to encode at a lower framerate. The pipeline is v4l2src ! capsfilter ! tee ! queue ! xvidenc ! avimux ! filesink and the tee also sinks to a queue ! xvimagesink sync=false. I've tried adding videorate in front of xvidenc but that seems to make things worse. I've considered spooling the uncompressed video to disk in this pipeline and encoding it in a background thread. What else could I do to solve this problem? Is xvidenc or avimux doing the wrong thing with dropped frames? Could I dramatically increase the size of the queue preceding my encoder?
How can I record live video with gstreamer without dropping frames?
1.2
0
0
3,103
677,641
2009-03-24T14:28:00.000
2
1
1
0
python,linux,gstreamer
2,237,878
2
false
0
0
and you need to write xvimagesink, not xvimagesync
2
4
0
I'm trying to use gstreamer 0.10 from Python to simultaneously display a v4l2 video source and record it to xvid-in-avi. Over a long period of time the computer would be fast enough to do this but if another program uses the disk it drops frames. That's bad enough, but on playback there are bursts of movement in the video where frames were dropped instead of displaying the frames we were able to encode at a lower framerate. The pipeline is v4l2src ! capsfilter ! tee ! queue ! xvidenc ! avimux ! filesink and the tee also sinks to a queue ! xvimagesink sync=false. I've tried adding videorate in front of xvidenc but that seems to make things worse. I've considered spooling the uncompressed video to disk in this pipeline and encoding it in a background thread. What else could I do to solve this problem? Is xvidenc or avimux doing the wrong thing with dropped frames? Could I dramatically increase the size of the queue preceding my encoder?
How can I record live video with gstreamer without dropping frames?
0.197375
0
0
3,103
680,207
2009-03-25T04:23:00.000
4
0
1
0
python
680,227
5
false
0
0
If you are typing "python" to launch it, it is probably CPython. IronPython's executable name is "ipy".
1
4
0
I am using Python 2.5.2. How can I tell whether it is CPython or IronPython or Jython? Another question: how can I use a DLL developed in VB.NET in my project?
How do I tell which Python interpreter I'm using?
0.158649
0
0
6,072
680,336
2009-03-25T05:34:00.000
3
0
1
0
python,ironpython
680,367
1
true
0
1
You won't be able to run your script in that application. The script console in that QT application doubtlessly uses plain ol' CPython instead of IronPython. There's no real good way to change that without significant surgery to the application that's hosting the python console.
1
0
0
This is a continuation of my question Python2.5.2 The code i developed is working fine with clr.Addreference(). Now thee problem is I have to load ny script which uses dll developed in .NET to another application.They had used QT for its implementation.There is a Script console in that application.When ii entered 'import clr' ,it was saying 'No module named clr' or 'Cannot import clr'.What shall i do?
Python 2.5.2 continued
1.2
0
0
614
681,853
2009-03-25T14:33:00.000
1
1
1
0
.net,python,clr,ironpython
681,875
4
false
0
0
As far as I know you are not going to get anything more actively developed than IronPython . IronPython is currently one of the .NET 5 being developed by the language team (C#, VB.NET, F#, IronPython and IronRuby) so I doubt that there's another open source .NET Python project that's gone anywhere near as far.
2
3
0
Are there any alternatives to Python for .NET or IronPython for accessing .NET CLR? Both of these seem to have downsides in that Python for .NET is not under active development (as far as I can tell) and you lose some features available in CPython if you use IronPython. So are there any alternatives?
Any alternatives to IronPython, Python for .NET for accessing CLR from python?
0.049958
0
0
3,386
681,853
2009-03-25T14:33:00.000
4
1
1
0
.net,python,clr,ironpython
682,313
4
false
0
0
Apart from Python for .NET (which works pretty well for me), the only other solution I'm aware of is exposing the .NET libraries via COM interop, so you can use them via the pywin32 extensions. (I don't know much about .NET com interop yet, so hopefully someone else can provide further explanation on that.)
2
3
0
Are there any alternatives to Python for .NET or IronPython for accessing .NET CLR? Both of these seem to have downsides in that Python for .NET is not under active development (as far as I can tell) and you lose some features available in CPython if you use IronPython. So are there any alternatives?
Any alternatives to IronPython, Python for .NET for accessing CLR from python?
0.197375
0
0
3,386
682,799
2009-03-25T18:08:00.000
1
0
0
1
python,command-line,windows-console
4,378,603
6
false
0
0
I got the same message but it was strange because the command was not that long (130 characters) and it used to work, it just stopped working one day. I just closed the command window and opened a new one and it worked. I have had the command window opened for a long time (maybe months, it's a remote virtual machine). I guess is some windows bug with a buffer or something.
2
10
0
I am trying to use os.system() to call another program that takes an input and an output file. The command I use is ~250 characters due to the long folder names. When I try to call the command, I'm getting an error: The input line is too long. I'm guessing there's a 255 character limit (its built using a C system call, but I couldn't find the limitations on that either). I tried changing the directory with os.chdir() to reduce the folder trail lengths, but when I try using os.system() with "..\folder\filename" it apparently can't handle relative path names. Is there any way to get around this limit or get it to recognize relative paths?
What to do with "The input line is too long" error message?
0.033321
0
0
26,102
682,799
2009-03-25T18:08:00.000
1
0
0
1
python,command-line,windows-console
682,807
6
false
0
0
Assuming you're using windows, from the backslashes, you could write a .bat file from python and then os.system() on that. It's a hack.
2
10
0
I am trying to use os.system() to call another program that takes an input and an output file. The command I use is ~250 characters due to the long folder names. When I try to call the command, I'm getting an error: The input line is too long. I'm guessing there's a 255 character limit (its built using a C system call, but I couldn't find the limitations on that either). I tried changing the directory with os.chdir() to reduce the folder trail lengths, but when I try using os.system() with "..\folder\filename" it apparently can't handle relative path names. Is there any way to get around this limit or get it to recognize relative paths?
What to do with "The input line is too long" error message?
0.033321
0
0
26,102
683,273
2009-03-25T20:18:00.000
2
1
1
0
c#,python
687,099
10
false
0
0
I'm pretty much in your shoes too, still using C# for most of my work, but using Python more and more for other projects. @e-satis probably knows Python inside-out and all his advice is top-notch. From my point of view what made the biggest difference to me was the following: Get back into functional. not necessarily spaghetti code, but learning that not everything has to be in an object, nor should it be. The interpreter. It's like the immediate window except 10^10 better. Because of how Python works you don't need all the baggage and crap C# makes you put in before you can run things; you can just whack in a few lines and see how things work. I've normally got an IDLE instance up where I just throw around snippets as I'm working out how the various bits in the language works while I'm editing my files... e.g. busy working out how to do a map call on a list, but I'm not 100% on the lambda I should use... whack in a few lines into IDLE, see how it works and what it does. And finally, loving into the verbosity of Python, and I don't mean that in the long winded meaning of verbosity, but as e-satis pointed out, using verbs like "in", "is", "for", etc. If you did a lot of reflection work in C# you'll feel like crying when you see how simple the same stuff is in Python. Good luck with it.
2
74
0
I've mainly been doing C# development for the past few years but recently started to do a bit of Python (not Iron Python). But I'm not sure if I've made the mental leap to Python...I kind of feel I'm trying to do things as I would in C#. Any advice on how I can fully take advantage of Python? Or any tips\tricks, things to learn more about, things to watch out for?
Advice for C# programmer writing Python
0.039979
0
0
12,232
683,273
2009-03-25T20:18:00.000
16
1
1
0
c#,python
683,362
10
false
0
0
Refrain from using classes. Use dictionaries, sets, list and tuples. Setters and getters are forbidden. Don't have exception handlers unless you really need to - let it crash in style. Pylint can be your friend for more pythonish coding style. When you're ready - check out list comprehensions, generators and lambda functions.
2
74
0
I've mainly been doing C# development for the past few years but recently started to do a bit of Python (not Iron Python). But I'm not sure if I've made the mental leap to Python...I kind of feel I'm trying to do things as I would in C#. Any advice on how I can fully take advantage of Python? Or any tips\tricks, things to learn more about, things to watch out for?
Advice for C# programmer writing Python
1
0
0
12,232
683,493
2009-03-25T21:17:00.000
2
0
0
0
python,httpwebrequest
683,519
3
true
0
0
Set the HTTP request timeout.
1
1
0
Very occasionally when making a http request, I am waiting for an age for a response that never comes. What is the recommended way to cancel this request after a reasonable period of time?
Timeout on a HTTP request in python
1.2
0
1
578
684,171
2009-03-26T01:19:00.000
38
0
1
0
python
684,229
11
false
0
0
So, far I have been exiting and reentering the Interpreter because re importing the file again is not working for me. Yes, just saying import again gives you the existing copy of the module from sys.modules. You can say reload(module) to update sys.modules and get a new copy of that single module, but if any other modules have a reference to the original module or any object from the original module, they will keep their old references and Very Confusing Things will happen. So if you've got a module a, which depends on module b, and b changes, you have to ‘reload b’ followed by ‘reload a’. If you've got two modules which depend on each other, which is extremely common when those modules are part of the same package, you can't reload them both: if you reload p.a it'll get a reference to the old p.b, and vice versa. The only way to do it is to unload them both at once by deleting their items from sys.modules, before importing them again. This is icky and has some practical pitfalls to do with modules entries being None as a failed-relative-import marker. And if you've got a module which passes references to its objects to system modules — for example it registers a codec, or adds a warnings handler — you're stuck; you can't reload the system module without confusing the rest of the Python environment. In summary: for all but the simplest case of one self-contained module being loaded by one standalone script, reload() is very tricky to get right; if, as you imply, you are using a ‘package’, you will probably be better off continuing to cycle the interpreter.
1
448
0
I often test my module in the Python Interpreter, and when I see an error, I quickly update the .py file. But how do I make it reflect on the Interpreter ? So, far I have been exiting and reentering the Interpreter because re importing the file again is not working for me.
How to re import an updated package while in Python Interpreter?
1
0
0
297,115
685,533
2009-03-26T12:24:00.000
0
0
0
1
python,linux,ms-office
685,656
7
false
0
0
I've had some success at using XSLT to process the XML-based office files into something usable in the past. It's not necessarily a python-based solution, but it does get the job done.
1
11
0
Any recomendations on a method to convert .doc, .ppt, and .xls to plain text on linux using python? Really any method of conversion would be useful. I have already looked at using Open Office but, I would like a solution that does not require having to install Open Office.
python convert microsoft office docs to plain text on linux
0
0
0
11,214
685,671
2009-03-26T13:01:00.000
0
0
1
0
python
970,635
9
false
0
0
the solutions based on 'set' have a small drawback, namely they only work for hashable objects. the solution based on itertools.groupby on the other hand works for all comparable objects (e.g.: dictionaries and lists).
1
0
0
I have a list of strings that should be unique. I want to be able to check for duplicates quickly. Specifically, I'd like to be able to take the original list and produce a new list containing any repeated items. I don't care how many times the items are repeated so it doesn't have to have a word twice if there are two duplicates. Unfortunately, I can't think of a way to do this that wouldn't be clunky. Any suggestions? EDIT: Thanks for the answers and I thought I'd make a clarification. I'm not concerned with having a list of uniques for it's own sake. I'm generating the list based off of text files and I want to know what the duplicates are so I can go in the text files and remove them if any show up.
In Python, how do I take a list and reduce it to a list of duplicates?
0
0
0
837
687,703
2009-03-26T21:52:00.000
0
1
1
0
python,io,global-variables
687,855
3
false
0
0
Nope. Variables are too specific to be passed around in the global namespace. Hide them inside static functions/classes instead that can do magic things to them at run time (or call other ones entirely). Consider what happens if the IO can periodically change state or if it needs to block for a while (like many sockets do). Consider what happens if the same block of code is included multiple times. Does the variable instance get duplicated as well? Consider what happens if you want to have a version 2 of the same variable. What if you want to change its interface? Do you have to modify all the code that references it? Does it really make sense to infect all the code that uses the variable with knowledge of all the ways it can go bad?
2
5
0
I'm programming a game in Python, where all IO activities are done by an IO object (in the hope that it will be easy to swap that object out for another which implements a different user interface). Nearly all the other objects in the game need to access the IO system at some point (e.g. printing a message, updating the position of the player, showing a special effect caused by an in-game action), so my question is this: Does it make sense for a reference to the IO object to be available globally? The alternative is passing a reference to the IO object into the __init__() of every object that needs to use it. I understand that this is good from a testing point of view, but is this worth the resulting "function signature pollution"? Thanks.
Python game programming: is my IO object a legitimate candidate for being a global variable?
0
0
0
250
687,703
2009-03-26T21:52:00.000
1
1
1
0
python,io,global-variables
687,782
3
false
0
0
Yes, I think so. Another possibility would be to create a module loggerModule that has functions like print() and write(), but this would only marginally be better.
2
5
0
I'm programming a game in Python, where all IO activities are done by an IO object (in the hope that it will be easy to swap that object out for another which implements a different user interface). Nearly all the other objects in the game need to access the IO system at some point (e.g. printing a message, updating the position of the player, showing a special effect caused by an in-game action), so my question is this: Does it make sense for a reference to the IO object to be available globally? The alternative is passing a reference to the IO object into the __init__() of every object that needs to use it. I understand that this is good from a testing point of view, but is this worth the resulting "function signature pollution"? Thanks.
Python game programming: is my IO object a legitimate candidate for being a global variable?
0.066568
0
0
250
688,302
2009-03-27T02:19:00.000
5
0
1
0
python,text-editor,tui
688,315
10
false
0
0
Curses type libraries and resources will get you into the textual user interfaces, and provide very nice, relatively easy to use windows, menus, editors, etc. Then you'll want to look into code highlighting modules for python. It's a fun process dealing with the limitations of textual interfaces, and you can learn a lot by going down this road. Good luck! -Adam
2
20
0
I have gotten to know my way around a few programming languages, and I'd like to try my hand at making a command-line text editor -- something that runs in the terminal, like vim/emacs/nano, but is pure text (no guis, please). Preferably, I'd like to do this in python. Where do I start? Are there any (python) libraries to do command-line applications?
How do I make a command line text editor?
0.099668
0
0
21,324
688,302
2009-03-27T02:19:00.000
2
0
1
0
python,text-editor,tui
688,313
10
false
0
0
Well, what do you mean by a GUI? If you just want to create something that can be used on a console, look into the curses module in the Python standard library, which allows you to simulate a primitive GUI of sorts on a console.
2
20
0
I have gotten to know my way around a few programming languages, and I'd like to try my hand at making a command-line text editor -- something that runs in the terminal, like vim/emacs/nano, but is pure text (no guis, please). Preferably, I'd like to do this in python. Where do I start? Are there any (python) libraries to do command-line applications?
How do I make a command line text editor?
0.039979
0
0
21,324
688,740
2009-03-27T06:36:00.000
17
1
1
0
php,python,dynamic-languages
688,756
4
true
0
0
Before you start refactoring you should create tests that will be able to test what you're going to change - if you say unit tests will not be enought, or they will be hard to create, then by all means create higher level tests possibly even excersising the whole of your product. If you have code coverage tools for your language use them to measure the quality of the tests that you've created - after it's reached a reasonably high value and if the tests are kept up to date and extended you'll be able to do anything with your code very efficiently and be rather sure things are not going in the wrong direction.
2
7
0
How to make sure that code is still working after refactoring ( i.e, after variable name change)? In static language, if a class is renamed but other referring class is not, then I will get a compilation error. But in dynamic language there is no such safety net, and your code can break during refactoring if you are not careful enough. You can use unit test, but when you are using mocks it's pretty hard to know the name changes and as a consequence, it may not help. How to solve this problem?
How to Make sure the code is still working after refactoring ( Dynamic language)
1.2
0
0
403
688,740
2009-03-27T06:36:00.000
0
1
1
0
php,python,dynamic-languages
1,813,232
4
false
0
0
1) For Python use PyUnit for PHP phpunit. 2) TDD approach is good but also making tests after writing code is acceptable. 3) Also use refactoring tools that are available for Your IDE they do only safe refactorings. In Python You have rope (this is library but have plugins for most IDEs). 4) Good books are: 'Test-Driven Development by example' Best 'Expert Python Programing' Tarek Ziade (explain both TDD and refactoring) google tdd and database to find a good book about TDD approach for developing databases. Add info for mocks you are using. AFAIK mocks are needed only when database or network is involved. But normally unit test should cover small pice of code (one class only) sometimes two classes so no mockup needed !!
2
7
0
How to make sure that code is still working after refactoring ( i.e, after variable name change)? In static language, if a class is renamed but other referring class is not, then I will get a compilation error. But in dynamic language there is no such safety net, and your code can break during refactoring if you are not careful enough. You can use unit test, but when you are using mocks it's pretty hard to know the name changes and as a consequence, it may not help. How to solve this problem?
How to Make sure the code is still working after refactoring ( Dynamic language)
0
0
0
403
689,560
2009-03-27T12:19:00.000
1
1
1
0
python,jpeg,python-imaging-library,fedora,libjpeg
689,629
2
false
0
0
Turns out this gets solved by completely removing the installed versions of PIL and starting the build again from scratch.
1
3
0
I'm on Fedora Core 6 (64 bit) after "yum install libjpeg-devel" I have downloaded and built PIL. It gives the message: --- JPEG support ok Looks like JPEG built okay, but when running selftest.py: IOError: decoder jpeg not available Why would it appear to have built correctly, but fail the selftest?
Building Python PIL for JPEG looks okay, but fails the selftest
0.099668
0
0
2,349
690,527
2009-03-27T16:45:00.000
3
1
0
0
python,email,pop3,fetchmail
690,536
4
false
0
0
Pop doesn't support sent email. Pop is an inbox only, Sent mail will be stored in IMAP, Exchange or other proprietary system.
4
0
0
I have been asked to quote a project where they want to see sent email using POP. I am pretty sure this is not possible, but I thought if it was. So is it possible given a users POP email server details to access their sent mail? If so any examples in Python or fetchmail?
Is it possible to Access a Users Sent Email over POP?
0.148885
0
1
3,820
690,527
2009-03-27T16:45:00.000
1
1
0
0
python,email,pop3,fetchmail
690,541
4
false
0
0
The smtp (mail sending) server could forward a copy of all sent mail back to the sender, they could then access this over pop.
4
0
0
I have been asked to quote a project where they want to see sent email using POP. I am pretty sure this is not possible, but I thought if it was. So is it possible given a users POP email server details to access their sent mail? If so any examples in Python or fetchmail?
Is it possible to Access a Users Sent Email over POP?
0.049958
0
1
3,820
690,527
2009-03-27T16:45:00.000
5
1
0
0
python,email,pop3,fetchmail
690,542
4
true
0
0
POP3 only handles receiving email; sent mail is sent via SMTP in these situations, and may be sent via a different ISP to the receiver (say, when you host your own email server, but use your current ISP to send). As such, this isn't directly possible. IMAP could do it, as this offers server side email folders as well as having the server handle the interface to both send and receive SMTP traffic
4
0
0
I have been asked to quote a project where they want to see sent email using POP. I am pretty sure this is not possible, but I thought if it was. So is it possible given a users POP email server details to access their sent mail? If so any examples in Python or fetchmail?
Is it possible to Access a Users Sent Email over POP?
1.2
0
1
3,820
690,527
2009-03-27T16:45:00.000
1
1
0
0
python,email,pop3,fetchmail
690,540
4
false
0
0
Emails are not sent using POP, but collected from a server using POP. They are sent using SMTP, and they don't hang around on the server once they're gone. You might want to look into IMAP?
4
0
0
I have been asked to quote a project where they want to see sent email using POP. I am pretty sure this is not possible, but I thought if it was. So is it possible given a users POP email server details to access their sent mail? If so any examples in Python or fetchmail?
Is it possible to Access a Users Sent Email over POP?
0.049958
0
1
3,820
690,856
2009-03-27T18:05:00.000
4
1
0
0
php,python,django,codeigniter
691,231
3
false
1
0
Deployment is clearly a problem for all non-PHP based web apps, but I think things are getting better with the DreamHost/Engineyard type ISP's who provide Ruby/Python etc. out of the box. It also looks like there's going to be a lot of discussion at PyCon this week about ways to fix deployment problems. The growth in popularity of Django, Turbogears, and Pylons is driving demand for better deployment solutions. That said, if your target market are people hosting on the very low end $12 a year type ISP's then I don't think you have much choice other than PHP. Finally, one thing I disagree with you is running PHP and Django on the same server. I'm running a few PHP apps on my server with Apache and dozens of Django sites with mod_wsgi in daemon mode. Running it that way means the Python interpreter doesn't use up ram in the Apache workers and vice versa, the PHP interpreter isn't contaminating my mod_wsgi daemons :)
3
8
0
I'm going to build a turn-key solution for a vertical market, and would like to offer both options: software as a service, and give them the opportunity to host the application on their own. In other words, I'm aiming to have similar deployment options as Joel's FogBugz. I'm a Python programmer, and I could fly over the project with Django. There are several reasons I prefer PHP though: 1) Django installation, and configuration assumes you have access to a shell (my target is not the programmer type). Although I could offer installation service, but not on their servers. 2) Django runs only on some specific hosts that must take special care to enable it. Installing mod_python/mod_wsgi, and most likely the minority of my potential clients would have root access, or even a cpanel. 3) Using PHP would mean I could run it on their existing server. I would have no need to move them to a Django-enabled server, and no downtime for their emails, while the DNS updates. On the other hand, I have very little experience with PHP. Smarty as a templating language looks nice, and works similarly to Django templates. It doesn't offer template inheritance though, except in a very hackish way in which I wish not to use as it could break the application if the designer messes them up. What do you think? Thanks in advance!
Django or CodeIgniter for Turn-Key Web Application
0.26052
0
0
6,522
690,856
2009-03-27T18:05:00.000
3
1
0
0
php,python,django,codeigniter
691,549
3
false
1
0
If you want your application to be mainstream then your almost forced to go with PHP. Going from Django to PHP is alot easier than going from PHP to Django. You know the standards, you just need to learn the PHP syntax and functions. I would definitely use a PHP framework. Symfony and akelos are very similar to Rails (close to Django). On the other than theres Code Igniter which does what it should - organise your code.
3
8
0
I'm going to build a turn-key solution for a vertical market, and would like to offer both options: software as a service, and give them the opportunity to host the application on their own. In other words, I'm aiming to have similar deployment options as Joel's FogBugz. I'm a Python programmer, and I could fly over the project with Django. There are several reasons I prefer PHP though: 1) Django installation, and configuration assumes you have access to a shell (my target is not the programmer type). Although I could offer installation service, but not on their servers. 2) Django runs only on some specific hosts that must take special care to enable it. Installing mod_python/mod_wsgi, and most likely the minority of my potential clients would have root access, or even a cpanel. 3) Using PHP would mean I could run it on their existing server. I would have no need to move them to a Django-enabled server, and no downtime for their emails, while the DNS updates. On the other hand, I have very little experience with PHP. Smarty as a templating language looks nice, and works similarly to Django templates. It doesn't offer template inheritance though, except in a very hackish way in which I wish not to use as it could break the application if the designer messes them up. What do you think? Thanks in advance!
Django or CodeIgniter for Turn-Key Web Application
0.197375
0
0
6,522
690,856
2009-03-27T18:05:00.000
2
1
0
0
php,python,django,codeigniter
692,907
3
false
1
0
Based on your own conclusions, I would go with CodeIgniter. It seems like there would be a ton of work helping your customers install your web app, and I assume you don't want that. Build a simple-to-install web app so that you can concentrate your efforts on making it better and selling it, instead of working extra as a sysadmin or writing extensive installation tutorials. (With that said, FogBugz wasn't easy to install on our Linux server, even though it is written in PHP. It took me and my colleague (both programmers!) more than a full work day to install. So I think there will always be problems with installation of self-hosted web apps.)
3
8
0
I'm going to build a turn-key solution for a vertical market, and would like to offer both options: software as a service, and give them the opportunity to host the application on their own. In other words, I'm aiming to have similar deployment options as Joel's FogBugz. I'm a Python programmer, and I could fly over the project with Django. There are several reasons I prefer PHP though: 1) Django installation, and configuration assumes you have access to a shell (my target is not the programmer type). Although I could offer installation service, but not on their servers. 2) Django runs only on some specific hosts that must take special care to enable it. Installing mod_python/mod_wsgi, and most likely the minority of my potential clients would have root access, or even a cpanel. 3) Using PHP would mean I could run it on their existing server. I would have no need to move them to a Django-enabled server, and no downtime for their emails, while the DNS updates. On the other hand, I have very little experience with PHP. Smarty as a templating language looks nice, and works similarly to Django templates. It doesn't offer template inheritance though, except in a very hackish way in which I wish not to use as it could break the application if the designer messes them up. What do you think? Thanks in advance!
Django or CodeIgniter for Turn-Key Web Application
0.132549
0
0
6,522
692,259
2009-03-28T05:14:00.000
0
0
1
0
python,animation,image-manipulation
692,396
2
false
0
0
Answer would depend on the platform and game too. e.g. I did once similar things for helicopter flash game, as it was very simple 2d game with well defined colored maze It was on widows with copy to clipboard and win32 key events using win32api bindings for python.
1
0
0
I want to automate playing a video game with Python. I want to write a script that can grab the screen image, diff it with the next frame and track an object to click on. What libraries would be useful for this other than PIL?
How do I track an animated object in Python?
0
0
0
331
693,752
2009-03-28T23:20:00.000
2
0
1
1
python,virtualbox
694,365
1
true
0
0
Consider using libvirt. The VirtualBox support is bleeding-edge (not in any release, may not even be in source control yet, but is available as a set of patches on the mailing list) -- but this single API, available for C, Python and several other languages, lets you control virtual machines and images running in Qemu/KVM, Xen, LXC (Linux Containers), UML (User-Mode Linux), OpenVZ and others. I build and administer virtual appliances (in an automated QA context) using libvirt with the qemu/KVM backend, and it meets my needs very well. libvirt can be configured to allow remote access (such as controlling or querying VBoxService or libvirtd from within one of the VMs, which you appear to want to do -- though I question the wisdom and utility), with numerous authentication and transport options available. [Caveat: libvirt principally targets Unixlike operating systems; it can be built for win32, but YMMV]
1
2
0
I want to make some python scripts to create an "Appliance" with VirtualBox. However, I can't find any documentation anywhere on making calls to VBoxService.exe. Well, I've found stuff that works from OUTSIDE the Machine, but nothing from working from inside the machine. Does anyone know anything about this? If there's a library for another language like C I'd be okay with it, though Python would be heavily preferred.
Python module for VBox?
1.2
0
0
1,234
696,792
2009-03-30T11:12:00.000
0
1
1
0
python
697,052
5
false
0
0
I agree with 'create a package'. If you cannot do that, how about using symbolic links/junctions (ln -s on Linux, linkd on Windows)?
2
5
0
Lets say I have projects x and y in brother directories: projects/x and projects/y. There are some utility funcs common to both projects in myutils.py and some db stuff in mydbstuff.py, etc. Those are minor common goodies, so I don't want to create a single package for them. Questions arise about the whereabouts of such files, possible changes to PYTHONPATH, proper way to import, etc. What is the 'pythonic way' to use such files?
What is the pythonic way to share common files in multiple projects?
0
0
0
426
696,792
2009-03-30T11:12:00.000
9
1
1
0
python
696,825
5
true
0
0
The pythonic way is to create a single extra package for them. Why don't you want to create a package? You can distribute this package with both projects, and the effect would be the same. You'll never do it right for all instalation scenarios and platforms if you do it by mangling with PYTHONPATH and custom imports. Just create another package and be done in no time.
2
5
0
Lets say I have projects x and y in brother directories: projects/x and projects/y. There are some utility funcs common to both projects in myutils.py and some db stuff in mydbstuff.py, etc. Those are minor common goodies, so I don't want to create a single package for them. Questions arise about the whereabouts of such files, possible changes to PYTHONPATH, proper way to import, etc. What is the 'pythonic way' to use such files?
What is the pythonic way to share common files in multiple projects?
1.2
0
0
426
697,142
2009-03-30T13:14:00.000
1
0
0
0
python,eclipse,eclipse-plugin,pydev
698,968
2
false
1
0
project properties (right click project in left pane) Go to "run/debug settings", add a new profile. Setup the path and environment etc... you want to launch. The new configuration will show up in your build menu. You could also configure it as an "external tool"
1
14
0
I'm learning Python and Django using the Eclipse Pydev plugin. I want the internal or external browser to launch or refresh with the URL http:/127.0.0.1 when I press Run or Debug. I've seen it done with the PHP plugins but not Pydev.
How do I configure Eclipse to launch a browser when Run or Debug is selected using Pydev plugin
0.099668
0
0
12,436
697,320
2009-03-30T13:58:00.000
5
1
0
0
python,class,introspection
697,405
3
false
1
0
This is the wrong approach for Django and really forcing things. The typical Django app pattern is: /project /appname models.py views.py /templates index.html etc.
1
121
0
Given a class C in Python, how can I determine which file the class was defined in? I need something that can work from either the class C, or from an instance off C. The reason I am doing this, is because I am generally a fan off putting files that belong together in the same folder. I want to create a class that uses a Django template to render itself as HTML. The base implementation should infer the filename for the template based on the filename that the class is defined in. Say I put a class LocationArtifact in the file "base/artifacts.py", then I want the default behaviour to be that the template name is "base/LocationArtifact.html".
How do I get the filepath for a class in Python?
0.321513
0
0
56,627
697,594
2009-03-30T15:05:00.000
1
1
0
0
java,python,reporting,birt
716,222
1
false
0
0
What kind of integration are you talking about? If you want to call some BIRT API the I gues it could be done from Jython as Jython can call any Java API. If you don't need to call the BIRT API then you can just get the birt reports with http requests from the BIRT report server (a tomcat application).
1
3
0
Has anyone ever tried that?
How to integrate BIRT with Python
0.197375
0
0
4,155
697,749
2009-03-30T15:40:00.000
0
1
0
0
c++,python,swig
698,089
2
false
0
1
If split properly, the modules don't necessarily need to have the same dependencies as the others - just what's necessary to do compilation. If you break things up appropriately, you can have libraries without cyclic dependencies. The issue with using multiple libraries is that by default, SWIG declares its runtime code statically, and as a result, as problems passing objects from one module to another. You need to enable a shared version of the SWIG runtime code. From the documentation (SWIG web page documentation link is broken): The runtime functions are private to each SWIG-generated module. That is, the runtime functions are declared with "static" linkage and are visible only to the wrapper functions defined in that module. The only problem with this approach is that when more than one SWIG module is used in the same application, those modules often need to share type information. This is especially true for C++ programs where SWIG must collect and share information about inheritance relationships that cross module boundaries. Check out that section in your downloaded documentation (section 16.2 The SWIG runtime code), and it'll give you details on how to enable this so that objects can be properly handled when passed from one module to the other. FWIW, I've not worked with Python SWIG, but have done Tcl SWIG.
1
9
0
I hit this issue about two years ago when I first implemented our SWIG bindings. As soon as we exposed a large amount of code we got to the point where SWIG would output C++ files so large the compiler could not handle them. The only way I could get around the issue was to split up the interfaces into multiple modules and to compile them separately. This has several downsides: • Each module must know about dependencies in other modules. I have a script to generate the interface files which handles this side of things, but it adds extra complexity. • Each additional module increases the time that the dynamic linker requires to load in the code. I have added an init.py file that imports all the submodules, so that the fact that the code is split up is transparent to the user, but what is always visible is the long load times. I'm currently reviewing our build scripts / build process and I wanted to see if I could find a solution to this issue that was better than what I have now. Ideally, I'd have one shared library containing all the wrapper code. Does anyone know how I can acheive this with SWIG? I've seen some custom code written in Ruby for a specific project, where the output is post-processed to make this possible, but when I looked at the feasibility for Python wrappers it does not look so easy.
Is it possible to split a SWIG module for compilation, but rejoin it when linking?
0
0
0
2,117
697,776
2009-03-30T15:49:00.000
0
0
1
0
python,bash,mp3,m4a
698,252
5
false
1
0
You can just write a simple app with a mapping of each tag name in each format to an "abstract tag" type, and then its easy to convert from one to the other. You don't even have to know all available types - just those that you are interested in. Seems to me like a weekend-project type of time investment, possibly less. Have fun, and I won't mind taking a peek at your implementation and even using it - if you won't mind releasing it of course :-) .
2
14
0
I'm looking for a resource in python or bash that will make it easy to take, for example, mp3 file X and m4a file Y and say "copy X's tags to Y". Python's "mutagen" module is great for manupulating tags in general, but there's no abstract concept of "artist field" that spans different types of tag; I want a library that handles all the fiddly bits and knows fieldname equivalences. For things not all tag systems can express, I'm okay with information being lost or best-guessed. (Use case: I encode lossless files to mp3, then go use the mp3s for listening. Every month or so, I want to be able to update the 'master' lossless files with whatever tag changes I've made to the mp3s. I'm tired of stubbing my toes on implementation differences among formats.)
abstracting the conversion between id3 tags, m4a tags, flac tags
0
0
0
4,835
697,776
2009-03-30T15:49:00.000
0
0
1
0
python,bash,mp3,m4a
740,815
5
false
1
0
There's also tagpy, which seems to work well.
2
14
0
I'm looking for a resource in python or bash that will make it easy to take, for example, mp3 file X and m4a file Y and say "copy X's tags to Y". Python's "mutagen" module is great for manupulating tags in general, but there's no abstract concept of "artist field" that spans different types of tag; I want a library that handles all the fiddly bits and knows fieldname equivalences. For things not all tag systems can express, I'm okay with information being lost or best-guessed. (Use case: I encode lossless files to mp3, then go use the mp3s for listening. Every month or so, I want to be able to update the 'master' lossless files with whatever tag changes I've made to the mp3s. I'm tired of stubbing my toes on implementation differences among formats.)
abstracting the conversion between id3 tags, m4a tags, flac tags
0
0
0
4,835
697,866
2009-03-30T16:11:00.000
10
1
0
0
python,frameworks,seaside
698,677
9
true
1
0
Disclaimer: I really don't like PHP, Python is nice, but doesn't come close to Smalltalk in my book. But I am a biased Smalltalker. Some answers about Seaside/Squeak: Q: Which I guess runs on a squeak app server? Seaside runs in several different Smalltalks (VW, Gemstone, Squeak etc). The term "app server" is not really used in Smalltalk country. :) Q: From what I've heard it would permit good compartmentalization of users as each would have their own little private VM independent of all the systems other users which sounds wonderful from a security, scaling and redundancy standpoint. Yes, each user has its own WASession and all UI components the user sees are instances living on the server side in that session. So sharing of state between sessions is something you must do explicitly, typically through a db. Q: I've not done any Smalltalk since Uni 15 years back and I never dug too deep into it then. I don't see much entry level help for seaside or that many projects using it. Smalltalk is easy to get going with and there is a whole free online book on Seaside. Q: I suspect setting a server up to run it is hard for the same reason i.e. not because it's inherently hard but just cause there will be less help online and a presumption you are already rather au fait with Sqeak/Smalltalk. No, not hard. :) In fact, quite trivial. Tons of help - Seaside ml, IRC on freenode, etc. Q: Is Seaside as good as I think in terms of insulating users from each other? I would say so. Q: Might I be better off, security wise, sticking to the languages I'm most familiar with so I don't make any n00b mistakes or will Seaside be worth worth scaling the learning curve and prove more secure, comprehensible and maintainable in the long run? The killer argument in favor of Seaside IMHO is the true component model. It really, really makes it wonderful for complex UIs and maintenance. If you are afraid of learning "something different" (but then you wouldn't even consider it in the first place I guess) then I would warn you. But if you are not afraid then you will probably love it. Also - Squeak (or VW) is a truly awesome development environment - debugging live Seaside sessions, changing code in the debugger and resuming etc etc. It rocks.
3
9
0
I know it's kinda subjective but, if you were to put yourself in my shoes which would you invest the time in learning? I want to write a web app which deals securely with relatively modest amounts of peoples private data, a few thousand records of a few Kb each but stuff that needs to be kept safe, addresses, phone numbers etc. I've done several web projects in PHP/MYSQL and have decided, handy though it is I really don't like PHP and don't want to do another large project in it... As such I figure I'd best learn something new and so I am considering 2 options (although I'll happily entertain others if you have suggestions). I'm having terrible trouble deciding though. They both look quite involved so rather than just jump in and potentially waste days getting up to speed enough on both of them to make an informed choice I thought I'd come here and canvas some opinion. So the two options I'm considering are... One of the PYTHON Web frameworks - TurboGears seems well regarded? Advantage: Of all the languages I ever tried Python is by far and away my favorite. There's loads of frameworks to choose from and I have done quite a lot of non web python coding over the last few years. Disadvantage: There's loads to choose from so it's hard to pick! Need to run single server process? or mod_python? which I don't like the sound of. What I do like is the notion of process separation and compartmentalization, i.e. if one users account is compromised it gives an attacker no leverage against the rest of the system. I'm not clear to what extent a python solution would handle that. Writing it as a SEASIDE app Which I guess runs on a squeak app server? Adv: From what I've heard it would permit good compartmentalization of users as each would have their own little private VM independent of all the systems other users which sounds wonderful from a security, scaling and redundancy standpoint. Dis: I've not done any Smalltalk since Uni 15 years back and I never dug too deep into it then. I don't see much entry level help for seaside or that many projects using it. I suspect setting a server up to run it is hard for the same reason i.e. not because it's inherently hard but just cause there will be less help online and a presumption you are already rather au fait with Sqeak/Smalltalk. So, what do people think? Would I be able to efficiently get the kind of strong separation and compartmentalization I'm after with a Python framework? Is Seaside as good as I think in terms of insulating users from each other? Might I be better off, security wise, sticking to the languages I'm most familiar with so I don't make any n00b mistakes or will Seaside be worth worth scaling the learning curve and prove more secure, comprehensible and maintainable in the long run? At the end of the day it's not a life or death decision and I can always bail if I start with one and then hate it so pls nobody get all holy language war and start flaming anyone! ;-) Cheers for any replies this gets, Roger :)
Dilemma: Should I learn Seaside or a Python framework?
1.2
0
0
2,399
697,866
2009-03-30T16:11:00.000
6
1
0
0
python,frameworks,seaside
698,940
9
false
1
0
I've been getting into seaside myself but in many ways it is very hard to get started, which has nothing to do with the smalltalk which can be picked up extremely quickly. The challenge is that you are really protected from writing html directly. I find in most frameworks when you get stuck on how to do something there is always a work around of solving it by using the template. You may later discover that this solution causes problems with clarity down the road and there is in fact a better solutions built into the framework but you were able to move on from that problem until you learned the right way to do it. Seaside doesn't have templates so you don't get that crutch. No problems have permanently stumped me but some have taken me longer to solve than I would have liked. The flip side of this is you end up learning the seaside methodology much quicker because you can't cheat. If you decide to go the seaside route don't be afraid to post to the seaside mailing list at squeakfoundation.org. I found it intimidating at first because you don't see a lot of beginner questions there due to the low traffic but people are willing to help beginners there. Also there are a handful of seaside developers who monitor stackoverflow regularly. Good luck.
3
9
0
I know it's kinda subjective but, if you were to put yourself in my shoes which would you invest the time in learning? I want to write a web app which deals securely with relatively modest amounts of peoples private data, a few thousand records of a few Kb each but stuff that needs to be kept safe, addresses, phone numbers etc. I've done several web projects in PHP/MYSQL and have decided, handy though it is I really don't like PHP and don't want to do another large project in it... As such I figure I'd best learn something new and so I am considering 2 options (although I'll happily entertain others if you have suggestions). I'm having terrible trouble deciding though. They both look quite involved so rather than just jump in and potentially waste days getting up to speed enough on both of them to make an informed choice I thought I'd come here and canvas some opinion. So the two options I'm considering are... One of the PYTHON Web frameworks - TurboGears seems well regarded? Advantage: Of all the languages I ever tried Python is by far and away my favorite. There's loads of frameworks to choose from and I have done quite a lot of non web python coding over the last few years. Disadvantage: There's loads to choose from so it's hard to pick! Need to run single server process? or mod_python? which I don't like the sound of. What I do like is the notion of process separation and compartmentalization, i.e. if one users account is compromised it gives an attacker no leverage against the rest of the system. I'm not clear to what extent a python solution would handle that. Writing it as a SEASIDE app Which I guess runs on a squeak app server? Adv: From what I've heard it would permit good compartmentalization of users as each would have their own little private VM independent of all the systems other users which sounds wonderful from a security, scaling and redundancy standpoint. Dis: I've not done any Smalltalk since Uni 15 years back and I never dug too deep into it then. I don't see much entry level help for seaside or that many projects using it. I suspect setting a server up to run it is hard for the same reason i.e. not because it's inherently hard but just cause there will be less help online and a presumption you are already rather au fait with Sqeak/Smalltalk. So, what do people think? Would I be able to efficiently get the kind of strong separation and compartmentalization I'm after with a Python framework? Is Seaside as good as I think in terms of insulating users from each other? Might I be better off, security wise, sticking to the languages I'm most familiar with so I don't make any n00b mistakes or will Seaside be worth worth scaling the learning curve and prove more secure, comprehensible and maintainable in the long run? At the end of the day it's not a life or death decision and I can always bail if I start with one and then hate it so pls nobody get all holy language war and start flaming anyone! ;-) Cheers for any replies this gets, Roger :)
Dilemma: Should I learn Seaside or a Python framework?
1
0
0
2,399
697,866
2009-03-30T16:11:00.000
1
1
0
0
python,frameworks,seaside
697,934
9
false
1
0
I think you've pretty much summed up the pros and cons. Seaside isn't that hard to set up (I've installed it twice for various projects) but using it will definitely affect how you work--in addition to re-learning the language you'll probably have to adjust lots of assumptions about your work flow. It also depends on two other factors If other people will eventually be maintaining it, you'll have better luck finding python programmers If you are doing a highly stateful site, Seaside is going to beat the pants off any other framework I've seen.
3
9
0
I know it's kinda subjective but, if you were to put yourself in my shoes which would you invest the time in learning? I want to write a web app which deals securely with relatively modest amounts of peoples private data, a few thousand records of a few Kb each but stuff that needs to be kept safe, addresses, phone numbers etc. I've done several web projects in PHP/MYSQL and have decided, handy though it is I really don't like PHP and don't want to do another large project in it... As such I figure I'd best learn something new and so I am considering 2 options (although I'll happily entertain others if you have suggestions). I'm having terrible trouble deciding though. They both look quite involved so rather than just jump in and potentially waste days getting up to speed enough on both of them to make an informed choice I thought I'd come here and canvas some opinion. So the two options I'm considering are... One of the PYTHON Web frameworks - TurboGears seems well regarded? Advantage: Of all the languages I ever tried Python is by far and away my favorite. There's loads of frameworks to choose from and I have done quite a lot of non web python coding over the last few years. Disadvantage: There's loads to choose from so it's hard to pick! Need to run single server process? or mod_python? which I don't like the sound of. What I do like is the notion of process separation and compartmentalization, i.e. if one users account is compromised it gives an attacker no leverage against the rest of the system. I'm not clear to what extent a python solution would handle that. Writing it as a SEASIDE app Which I guess runs on a squeak app server? Adv: From what I've heard it would permit good compartmentalization of users as each would have their own little private VM independent of all the systems other users which sounds wonderful from a security, scaling and redundancy standpoint. Dis: I've not done any Smalltalk since Uni 15 years back and I never dug too deep into it then. I don't see much entry level help for seaside or that many projects using it. I suspect setting a server up to run it is hard for the same reason i.e. not because it's inherently hard but just cause there will be less help online and a presumption you are already rather au fait with Sqeak/Smalltalk. So, what do people think? Would I be able to efficiently get the kind of strong separation and compartmentalization I'm after with a Python framework? Is Seaside as good as I think in terms of insulating users from each other? Might I be better off, security wise, sticking to the languages I'm most familiar with so I don't make any n00b mistakes or will Seaside be worth worth scaling the learning curve and prove more secure, comprehensible and maintainable in the long run? At the end of the day it's not a life or death decision and I can always bail if I start with one and then hate it so pls nobody get all holy language war and start flaming anyone! ;-) Cheers for any replies this gets, Roger :)
Dilemma: Should I learn Seaside or a Python framework?
0.022219
0
0
2,399
699,177
2009-03-30T21:50:00.000
0
0
1
0
python
699,187
8
false
0
0
It has to store the length somewhere, so you aren't counting the number of items every time.
3
93
0
If I keep calling len() on a very long list, am I wasting time, or does it keep an int count in the background?
Python: Do Python Lists keep a count for len() or does it count for each call?
0
0
0
19,296
699,177
2009-03-30T21:50:00.000
3
0
1
0
python
699,211
8
false
0
0
A Python "list" is really a resizeable array, not a linked list, so it stores the size somewhere.
3
93
0
If I keep calling len() on a very long list, am I wasting time, or does it keep an int count in the background?
Python: Do Python Lists keep a count for len() or does it count for each call?
0.07486
0
0
19,296
699,177
2009-03-30T21:50:00.000
100
0
1
0
python
699,191
8
true
0
0
Don't worry: Of course it saves the count and thus len() on lists is a pretty cheap operation. Same is true for strings, dictionaries and sets, by the way!
3
93
0
If I keep calling len() on a very long list, am I wasting time, or does it keep an int count in the background?
Python: Do Python Lists keep a count for len() or does it count for each call?
1.2
0
0
19,296
699,325
2009-03-30T22:39:00.000
12
1
0
1
python,redirect
2,728,111
9
false
0
0
If your search engine lead you to this old question (like me), be aware that using PIPE may lead to deadlocks. Indeed, because pipes are buffered, you can write a certain number of bytes in a pipe, even if no one read it. However the size of buffer is finite. And consequently if your program A has an output larger than the buffer, A will be blocked on writing, while the calling program B awaits the termination of A. But not, in this particular case... see comments below. Still, I recommend using Devin Jeanpierre and DNS' solution.
1
45
0
I have a binary named A that generates output when called. If I call it from a Bash shell, most of the output is suppressed by A > /dev/null. All of the output is suppressed by A &> /dev/null I have a python script named B that needs to call A. I want to be able to generate output from B, while suppressing all the output from A. From within B, I've tried os.system('A'), os.system('A > /dev/null'), and os.system('A &> /dev/null'), os.execvp('...'), etc. but none of those suppress all the output from A. I could run B &> /dev/null, but that suppresses all of B's output too and I don't want that. Anyone have suggestions?
Suppress output in Python calls to executables
1
0
0
42,935
700,073
2009-03-31T05:06:00.000
2
0
1
0
python,multithreading,process,ctypes
700,142
4
true
0
0
There's two parts you'll need to answer here: one if how to communicate between the two processes (your GUI and the process executing the function), and the other is how to change your function so it responds to asynchronous requests ("oh, I've been told to just return whatever I've got"). Working out the answer to the second question will probably dictate the answer to the first. You could do it by signals (in which case you get a signal handler that gets control of the process, can look for more detailed instructions elsewhere, and change your internal data structures before returning control to your function), or you could have your function monitor a control interface for commands (every millisecond, check to see if there's a command waiting, and if there is, see what it is). In the first case, you'd want ANSI C signal handling (signal(), sighandler_t), in the second you'd probably want a pipe or similar (pipe() and select()).
3
2
0
I have a python GUI app that uses a long running function from a .so/.dll it calls through ctypes. I'm looking for a way to communicate with the function while it's running in a separate thread or process, so that I can request it to terminate early (which requires some work on the C side before returning a partial result). I suppose this will need some kind of signal receiving or reading from pipes, but I want to keep it as simple as possible. What would you consider the best approach to solve this kind of problem? I am able to change the code on both the python and C sides.
communication with long running tasks in python
1.2
0
0
714
700,073
2009-03-31T05:06:00.000
0
0
1
0
python,multithreading,process,ctypes
700,089
4
false
0
0
You said it: signals and pipes. It doesn't have to be too complex, but it will be a heck of a lot easier if you use an existing structure than if you try to roll your own.
3
2
0
I have a python GUI app that uses a long running function from a .so/.dll it calls through ctypes. I'm looking for a way to communicate with the function while it's running in a separate thread or process, so that I can request it to terminate early (which requires some work on the C side before returning a partial result). I suppose this will need some kind of signal receiving or reading from pipes, but I want to keep it as simple as possible. What would you consider the best approach to solve this kind of problem? I am able to change the code on both the python and C sides.
communication with long running tasks in python
0
0
0
714
700,073
2009-03-31T05:06:00.000
0
0
1
0
python,multithreading,process,ctypes
700,088
4
false
0
0
If you're on *nix register a signal handler for SIGUSR1 or SIGINT in your C program then from Python use os.kill to send the signal.
3
2
0
I have a python GUI app that uses a long running function from a .so/.dll it calls through ctypes. I'm looking for a way to communicate with the function while it's running in a separate thread or process, so that I can request it to terminate early (which requires some work on the C side before returning a partial result). I suppose this will need some kind of signal receiving or reading from pipes, but I want to keep it as simple as possible. What would you consider the best approach to solve this kind of problem? I am able to change the code on both the python and C sides.
communication with long running tasks in python
0
0
0
714
700,350
2009-03-31T07:07:00.000
2
0
0
0
python,pbx,genesys,pabx
700,425
4
true
1
0
If they are providing a C library, you can use ctypes to interact with it.
3
0
0
Genesys is a contact center platform that provides software for working with both hard and soft PBXs. There are also a number of ancillary services they provide to support the wider contact center business. I'm aware of the .NET and Java SDKs that Genesys supply on a first hand basis. Is there SDK support for any other languages and, specifically, is there an official Python library for interacting with their services? Alternatively, are there any 3rd party libraries that are designed to interact with Genesys services for Python?
What languages provide SDKs for interacting with Genesys services?
1.2
0
0
607
700,350
2009-03-31T07:07:00.000
0
0
0
0
python,pbx,genesys,pabx
4,862,326
4
false
1
0
What do you need to interact with exacly? The GIS provides soap calls for a lot of functions.
3
0
0
Genesys is a contact center platform that provides software for working with both hard and soft PBXs. There are also a number of ancillary services they provide to support the wider contact center business. I'm aware of the .NET and Java SDKs that Genesys supply on a first hand basis. Is there SDK support for any other languages and, specifically, is there an official Python library for interacting with their services? Alternatively, are there any 3rd party libraries that are designed to interact with Genesys services for Python?
What languages provide SDKs for interacting with Genesys services?
0
0
0
607
700,350
2009-03-31T07:07:00.000
0
0
0
0
python,pbx,genesys,pabx
7,123,654
4
false
1
0
There is neither a native C nor a Python library. Best bet is to use GIS as suggested.
3
0
0
Genesys is a contact center platform that provides software for working with both hard and soft PBXs. There are also a number of ancillary services they provide to support the wider contact center business. I'm aware of the .NET and Java SDKs that Genesys supply on a first hand basis. Is there SDK support for any other languages and, specifically, is there an official Python library for interacting with their services? Alternatively, are there any 3rd party libraries that are designed to interact with Genesys services for Python?
What languages provide SDKs for interacting with Genesys services?
0
0
0
607
701,802
2009-03-31T16:12:00.000
10
0
1
0
python,string,exec
48,054,410
14
false
0
0
It's worth mentioning, that' exec's brother exist as well called execfile if you want to call a python file. That is sometimes good if you are working in a third party package which have terrible IDE's included and you want to code outside of their package. Example: execfile('/path/to/source.py)' or: exec(open("/path/to/source.py").read())
3
459
0
How do I execute a string containing Python code in Python?
How do I execute a string containing Python code in Python?
1
0
0
430,791
701,802
2009-03-31T16:12:00.000
22
0
1
0
python,string,exec
17,378,416
14
false
0
0
Remember that from version 3 exec is a function! so always use exec(mystring) instead of exec mystring.
3
459
0
How do I execute a string containing Python code in Python?
How do I execute a string containing Python code in Python?
1
0
0
430,791
701,802
2009-03-31T16:12:00.000
13
0
1
0
python,string,exec
4,278,878
14
false
0
0
eval() is just for expressions, while eval('x+1') works, eval('x=1') won't work for example. In that case, it's better to use exec, or even better: try to find a better solution :)
3
459
0
How do I execute a string containing Python code in Python?
How do I execute a string containing Python code in Python?
1
0
0
430,791
702,861
2009-03-31T20:20:00.000
5
0
0
0
java,python
703,221
2
false
1
0
Of course, Jython allows you to use Java classes from within Python. It's an alternate way of looking at it that would allow much tighter integration of the Java code.
1
15
0
How do I do this?
Executing Java programs through Python
0.462117
0
0
33,606
703,262
2009-03-31T22:03:00.000
0
1
0
0
python,input,binaryfiles
703,588
4
false
0
0
I found that array.fromfile is the fastest methods for homogeneous data.
1
6
1
I have binary files no larger than 20Mb in size that have a header section and then a data section containing sequences of uchars. I have Numpy, SciPy, etc. and each library has different ways of loading in the data. Any suggestions for the most efficient methods I should use?
Most efficient way of loading formatted binary files in Python
0
0
0
450
703,925
2009-04-01T03:11:00.000
1
0
0
1
python,eclipse
10,695,484
4
false
0
0
I know this is a ancient post... but, in case of some newbee like me to get the better answer. I just using "Eclipse Marketplace" from the "Help" menu and search for keyword "python" or "PyDev" to get PyDev, and get it successfully installed. AND, you should add PyDev to the top-right dock. For the instance, my eclipse on my laptop's OSX is (Version: Indigo Service Release 2 Build id: 20120216-1857). Have fun, folks! :)
2
11
0
I setup PyDev with this path for the python interpreter /System/Library/Frameworks/Python.framework/Versions/2.5/Python since the one under /usr/bin were alias and Eclipse won't select it. I can run my python script now but cannot run the shell as an external tool. The message I get is variable references empty selection ${resource_loc} Same if I use {container_loc} Any thoughts ? Sunit
Using pydev with Eclipse on OSX
0.049958
0
0
11,573
703,925
2009-04-01T03:11:00.000
3
0
0
1
python,eclipse
884,296
4
false
0
0
Common practice seems to be to install an up-to-date Python 2.5 from python.org and use that instead of the system installation. I saw that recommended here and there when I got started on Mac OS X. It installs under /Library (as opposed to /System/Library) so the system Python is intact. Pydev has /Library/Frameworks/Python.framework/Versions/2.5/Resources/Python.app/Contents/MacOS/Python as its configured Python interpreter and all is well. Can't state for sure that your trouble is due only to using the system's Python installation; in any case this way I have no trouble. Also, this way when you fiddle with your development environment (install things in site-packages, upgrade Python), anything that uses the system Python is sure to be unaffected.
2
11
0
I setup PyDev with this path for the python interpreter /System/Library/Frameworks/Python.framework/Versions/2.5/Python since the one under /usr/bin were alias and Eclipse won't select it. I can run my python script now but cannot run the shell as an external tool. The message I get is variable references empty selection ${resource_loc} Same if I use {container_loc} Any thoughts ? Sunit
Using pydev with Eclipse on OSX
0.148885
0
0
11,573
704,152
2009-04-01T05:19:00.000
22
0
1
0
python,integer,char,type-conversion
704,157
4
false
0
0
ord and chr
1
395
0
I want to get, given a character, its ASCII value. For example, for the character a, I want to get 97, and vice versa.
How can I convert a character to a integer in Python, and viceversa?
1
0
0
631,220
704,203
2009-04-01T05:44:00.000
0
0
0
1
python,bash,unix,process,kill
704,223
7
false
0
0
One idea: Save the process's PID (returned by fork() in your child process) to a file, then either schedule a cron job to kill it or kill it manually, reading the PID from the file. Another option: Create a shell script wrapper that automatically kills and restarts the process. Same as above, but you can keep the PID in memory, sleep for as long as you need, kill the process, then loop.
1
0
0
I need to run a process, wait a few hours, kill it, and start it again. Is there an easy way that I can accomplish this with Python or Bash? I can run it in the background but how do I identify it to use kill on it?
How do I schedule a process' termination?
0
0
0
2,629
704,526
2009-04-01T08:08:00.000
0
0
1
0
python
704,562
7
false
0
0
With sorted lists a binary search is usually the fastest alghorythm. Could you please provide an example list and an example "missing alphabet"?
1
2
0
I'm trying to find the missing letter in the alphabet from the list with the least lines of code. If the list is sorted already (using list.sort()), what is the fastest or least lines of code to find the missing letter. If I know there are only one missing letter. (This is not any type of interview questions. I actually need to do this in my script where I want to put least amount of work in this process since it will be repeated over and over indeterministically)
python: finding a missing letter in the alphabet from a list - least lines of code
0
0
0
8,681
704,834
2009-04-01T09:54:00.000
0
0
0
0
python,django,workflow
704,838
10
false
1
0
I know there is an openerp, but it's not workflow.....
1
19
0
I'm searching for a workflow library/framework for Python. I'm astonished that there I cannot find anything which is simple and not attached to Zope/Plone. Does anyone know of an open-source, simple workflow library/framework. It's preferred to support Django, but not required.
Does anyone know about workflow frameworks/libraries in Python?
0
0
0
15,282
704,945
2009-04-01T10:35:00.000
0
0
0
1
python,chmod
704,953
5
false
0
0
Does it have to be python? You can also use find to do that : "find . -perm 775"
1
3
0
i want a python program that given a directory, it will return all directories within that directory that have 775 (rwxrwxr-x) permissions thanks!
check permissions of directories in python
0
0
0
15,588
706,101
2009-04-01T15:39:00.000
1
1
1
0
python,json,python-2.6
5,541,345
7
false
0
0
Even though _json is available, I've noticed json decoding is very slow on CPython 2.6.6. I haven't compared with other implementations, but I've switched to string manipulation when inside performance-critical loops.
1
45
0
I'm using the json module in Python 2.6 to load and decode JSON files. However I'm currently getting slower than expected performance. I'm using a test case which is 6MB in size and json.loads() is taking 20 seconds. I thought the json module had some native code to speed up the decoding? How do I check if this is being used? As a comparison, I downloaded and installed the python-cjson module, and cjson.decode() is taking 1 second for the same test case. I'd rather use the JSON module provided with Python 2.6 so that users of my code aren't required to install additional modules. (I'm developing on Mac OS X, but I getting a similar result on Windows XP.)
Python 2.6 JSON decoding performance
0.028564
0
0
37,359
707,242
2009-04-01T20:38:00.000
1
0
1
1
python,windows,py2exe
707,261
5
false
0
0
This is not the best way to do it, but you might consider using executable SFX Archive with both the .exe and .dll files inside, and setting it to execute your .exe file when it's double clicked.
2
16
0
is there a way to create a standalone .exe from a python script. Executables generated with py2exe can run only with pythonXX.dll. I'd like to obtain a fully standalone .exe which does not require to install the python runtime library. It looks like a linking problem but using static library instead the dynamic one and it would be also useful to apply a strip in order to remove the unused symbols. Any idea ? Thanks. Alessandro
Create a standalone windows exe which does not require pythonXX.dll
0.039979
0
0
9,499
707,242
2009-04-01T20:38:00.000
5
0
1
1
python,windows,py2exe
707,310
5
false
0
0
Due to how Windows' dynamic linker works you cannot use the static library if you use .pyd or .dll Python modules; DLLs loaded in Windows do not automatically share their symbol space with the executable and so require a separate DLL containing the Python symbols.
2
16
0
is there a way to create a standalone .exe from a python script. Executables generated with py2exe can run only with pythonXX.dll. I'd like to obtain a fully standalone .exe which does not require to install the python runtime library. It looks like a linking problem but using static library instead the dynamic one and it would be also useful to apply a strip in order to remove the unused symbols. Any idea ? Thanks. Alessandro
Create a standalone windows exe which does not require pythonXX.dll
0.197375
0
0
9,499
708,531
2009-04-02T06:35:00.000
0
0
0
0
python,xml,sax
715,813
4
false
1
0
You could load it into Firefox, if you don't have an XML editor. Firefox shows you the error.
3
0
0
I stripped some tags that I thought were unnecessary from an XML file. Now when I try to parse it, my SAX parser throws an error and says my file is not well-formed. However, I know every start tag has an end tag. The file's opening tag has a link to an XML schema. Could this be causing the trouble? If so, then how do I fix it? Edit: I think I've found the problem. My character data contains "&lt" and "&gt" characters, presumably from html tags. After being parsed, these are converted to "<" and ">" characters, which seems to bother the SAX parser. Is there any way to prevent this from happening?
Python SAX parser says XML file is not well-formed
0
0
1
2,338
708,531
2009-04-02T06:35:00.000
0
0
0
0
python,xml,sax
711,033
4
false
1
0
I would second recommendation to try to parse it using another XML parser. That should give an indication as to whether it's the document that's wrong, or parser. Also, the actual error message might be useful. One fairly common problem for example is that the xml declaration (if one is used, it's optional) must be the very first thing -- not even whitespace is allowed before it.
3
0
0
I stripped some tags that I thought were unnecessary from an XML file. Now when I try to parse it, my SAX parser throws an error and says my file is not well-formed. However, I know every start tag has an end tag. The file's opening tag has a link to an XML schema. Could this be causing the trouble? If so, then how do I fix it? Edit: I think I've found the problem. My character data contains "&lt" and "&gt" characters, presumably from html tags. After being parsed, these are converted to "<" and ">" characters, which seems to bother the SAX parser. Is there any way to prevent this from happening?
Python SAX parser says XML file is not well-formed
0
0
1
2,338
708,531
2009-04-02T06:35:00.000
2
0
0
0
python,xml,sax
708,546
4
false
1
0
I would suggest putting those tags back in and making sure it still works. Then, if you want to take them out, do it one at a time until it breaks. However, I question the wisdom of taking them out. If it's your XML file, you should understand it better. If it's a third-party XML file, you really shouldn't be fiddling with it (until you understand it better :-).
3
0
0
I stripped some tags that I thought were unnecessary from an XML file. Now when I try to parse it, my SAX parser throws an error and says my file is not well-formed. However, I know every start tag has an end tag. The file's opening tag has a link to an XML schema. Could this be causing the trouble? If so, then how do I fix it? Edit: I think I've found the problem. My character data contains "&lt" and "&gt" characters, presumably from html tags. After being parsed, these are converted to "<" and ">" characters, which seems to bother the SAX parser. Is there any way to prevent this from happening?
Python SAX parser says XML file is not well-formed
0.099668
0
1
2,338
708,762
2009-04-02T08:05:00.000
5
0
0
0
python,sqlalchemy
709,452
4
true
0
0
I don't think (correct me if I'm wrong) INSERT OR REPLACE is in any of the SQL standards; it's an SQLite-specific thing. There is MERGE, but that isn't supported by all dialects either. So it's not available in SQLAlchemy's general dialect. The cleanest solution is to use Session, as suggested by M. Utku. You could also use SAVEPOINTs to save, try: an insert, except IntegrityError: then rollback and do an update instead. A third solution is to write your INSERT with an OUTER JOIN and a WHERE clause that filters on the rows with nulls.
1
13
0
does anybody know what is the equivalent to SQL "INSERT OR REPLACE" clause in SQLAlchemy and its SQL expression language? Many thanks -- honzas
SQLAlchemy - INSERT OR REPLACE equivalent
1.2
1
0
20,634
709,397
2009-04-02T11:54:00.000
1
0
1
0
python,xcode,macos
851,810
4
false
0
0
There are no special facilities for working with non-Cocoa Python projects with Xcode. Therefore, you probably just want to create a project with the "Empty Project" template (under "Other") and just drag in your source code. For convenience, you may want to set up an executable in the project. You can do this by ctrl/right-clicking in the project source list and choosing "Add" > "New Custom Executable...". You can also add a target, although I'm not sure what this would buy you.
1
6
0
I've got a python project I've been making in terminal with vim etc.. I've read that XCode supports Python development at that it supports SVN (which I am using) but I can't find documentation on how to start a new XCode project from an existing code repository. Other developers are working on the project not using XCode - They won't mind if I add a project file or something, but they will mind if I have to reorganise the whole thing.
Import an existing python project to XCode
0.049958
0
0
9,095
709,490
2009-04-02T12:21:00.000
27
0
1
0
python,conventions,pylint
709,709
3
true
0
0
Somehow some variable names are matched with the regex for constants (const-rgx) instead of the variable name regex (variable-rgx). Are those variables declared on module level? Maybe that's why they are treated as constants (at least that's how they should be declared, according to PEP-8).
1
10
0
I'm trying out pylint to check my source code for conventions. Somehow some variable names are matched with the regex for constants (const-rgx) instead of the variable name regex (variable-rgx). How to match the variable name with variable-rgx? Or should I extend const-rgx with my variable-rgx stuff? e.g. C0103: 31: Invalid name "settings" (should match (([A-Z_][A-Z1-9_]*)|(__.*__))$)
python code convention using pylint
1.2
0
0
9,144
710,551
2009-04-02T16:40:00.000
43
1
1
0
python,python-import
710,598
21
false
0
0
Both ways are supported for a reason: there are times when one is more appropriate than the other. import module: nice when you are using many bits from the module. drawback is that you'll need to qualify each reference with the module name. from module import ...: nice that imported items are usable directly without module name prefix. The drawback is that you must list each thing you use, and that it's not clear in code where something came from. Which to use depends on which makes the code clear and readable, and has more than a little to do with personal preference. I lean toward import module generally because in the code it's very clear where an object or function came from. I use from module import ... when I'm using some object/function a lot in the code.
6
535
0
I've tried to find a comprehensive guide on whether it is best to use import module or from module import. I've just started with Python and I'm trying to start off with best practices in mind. Basically, I was hoping if anyone could share their experiences, what preferences other developers have and what's the best way to avoid any gotchas down the road?
Use 'import module' or 'from module import'?
1
0
0
216,208
710,551
2009-04-02T16:40:00.000
4
1
1
0
python,python-import
710,831
21
false
0
0
To add to what people have said about from x import *: besides making it more difficult to tell where names came from, this throws off code checkers like Pylint. They will report those names as undefined variables.
6
535
0
I've tried to find a comprehensive guide on whether it is best to use import module or from module import. I've just started with Python and I'm trying to start off with best practices in mind. Basically, I was hoping if anyone could share their experiences, what preferences other developers have and what's the best way to avoid any gotchas down the road?
Use 'import module' or 'from module import'?
0.038077
0
0
216,208
710,551
2009-04-02T16:40:00.000
0
1
1
0
python,python-import
34,892,472
21
false
0
0
Import Module - You don't need additional efforts to fetch another thing from module. It has disadvantages such as redundant typing Module Import From - Less typing &More control over which items of a module can be accessed.To use a new item from the module you have to update your import statement.
6
535
0
I've tried to find a comprehensive guide on whether it is best to use import module or from module import. I've just started with Python and I'm trying to start off with best practices in mind. Basically, I was hoping if anyone could share their experiences, what preferences other developers have and what's the best way to avoid any gotchas down the road?
Use 'import module' or 'from module import'?
0
0
0
216,208
710,551
2009-04-02T16:40:00.000
1
1
1
0
python,python-import
62,796,069
21
false
0
0
since many people answered here but i am just trying my best :) import module is best when you don't know which item you have to import from module. In this way it may be difficult to debug when problem raises because you don't know which item have problem. form module import <foo> is best when you know which item you require to import and also helpful in more controlling using importing specific item according to your need. Using this way debugging may be easy because you know which item you imported.
6
535
0
I've tried to find a comprehensive guide on whether it is best to use import module or from module import. I've just started with Python and I'm trying to start off with best practices in mind. Basically, I was hoping if anyone could share their experiences, what preferences other developers have and what's the best way to avoid any gotchas down the road?
Use 'import module' or 'from module import'?
0.009524
0
0
216,208
710,551
2009-04-02T16:40:00.000
3
1
1
0
python,python-import
710,861
21
false
0
0
My own answer to this depends mostly on first, how many different modules I'll be using. If i'm only going to use one or two, I'll often use from ... import since it makes for fewer keystrokes in the rest of the file, but if I'm going to make use of many different modules, I prefer just import because that means that each module reference is self-documenting. I can see where each symbol comes from without having to hunt around. Usuaully I prefer the self documenting style of plain import and only change to from.. import when the number of times I have to type the module name grows above 10 to 20, even if there's only one module being imported.
6
535
0
I've tried to find a comprehensive guide on whether it is best to use import module or from module import. I've just started with Python and I'm trying to start off with best practices in mind. Basically, I was hoping if anyone could share their experiences, what preferences other developers have and what's the best way to avoid any gotchas down the road?
Use 'import module' or 'from module import'?
0.028564
0
0
216,208
710,551
2009-04-02T16:40:00.000
575
1
1
0
python,python-import
710,603
21
true
0
0
The difference between import module and from module import foo is mainly subjective. Pick the one you like best and be consistent in your use of it. Here are some points to help you decide. import module Pros: Less maintenance of your import statements. Don't need to add any additional imports to start using another item from the module Cons: Typing module.foo in your code can be tedious and redundant (tedium can be minimized by using import module as mo then typing mo.foo) from module import foo Pros: Less typing to use foo More control over which items of a module can be accessed Cons: To use a new item from the module you have to update your import statement You lose context about foo. For example, it's less clear what ceil() does compared to math.ceil() Either method is acceptable, but don't use from module import *. For any reasonable large set of code, if you import * you will likely be cementing it into the module, unable to be removed. This is because it is difficult to determine what items used in the code are coming from 'module', making it easy to get to the point where you think you don't use the import any more but it's extremely difficult to be sure.
6
535
0
I've tried to find a comprehensive guide on whether it is best to use import module or from module import. I've just started with Python and I'm trying to start off with best practices in mind. Basically, I was hoping if anyone could share their experiences, what preferences other developers have and what's the best way to avoid any gotchas down the road?
Use 'import module' or 'from module import'?
1.2
0
0
216,208
710,609
2009-04-02T16:53:00.000
8
1
1
0
python,module,version
710,653
7
true
0
0
I'd stay away from hashing. The version of libxslt being used might contain some type of patch that doesn't effect your use of it. As an alternative, I'd like to suggest that you don't check at run time (don't know if that's a hard requirement or not). For the python stuff I write that has external dependencies (3rd party libraries), I write a script that users can run to check their python install to see if the appropriate versions of modules are installed. For the modules that don't have a defined 'version' attribute, you can inspect the interfaces it contains (classes and methods) and see if they match the interface they expect. Then in the actual code that you're working on, assume that the 3rd party modules have the interface you expect.
2
136
0
Many third-party Python modules have an attribute which holds the version information for the module (usually something like module.VERSION or module.__version__), however some do not. Particular examples of such modules are libxslt and libxml2. I need to check that the correct version of these modules are being used at runtime. Is there a way to do this? A potential solution wold be to read in the source at runtime, hash it, and then compare it to the hash of the known version, but that's nasty. Is there a better solutions?
Checking a Python module version at runtime
1.2
0
0
83,866
710,609
2009-04-02T16:53:00.000
6
1
1
0
python,module,version
710,642
7
false
0
0
Some ideas: Try checking for functions that exist or don't exist in your needed versions. If there are no function differences, inspect function arguments and signatures. If you can't figure it out from function signatures, set up some stub calls at import time and check their behavior.
2
136
0
Many third-party Python modules have an attribute which holds the version information for the module (usually something like module.VERSION or module.__version__), however some do not. Particular examples of such modules are libxslt and libxml2. I need to check that the correct version of these modules are being used at runtime. Is there a way to do this? A potential solution wold be to read in the source at runtime, hash it, and then compare it to the hash of the known version, but that's nasty. Is there a better solutions?
Checking a Python module version at runtime
1
0
0
83,866
711,884
2009-04-02T22:31:00.000
30
0
1
0
python,naming-conventions
712,035
5
false
0
0
I know my solution is not very popular from the pythonic point of view, but I prefer to use the Java approach of one module->one class, with the module named as the class. I do understand the reason behind the python style, but I am not too fond of having a very large file containing a lot of classes. I find it difficult to browse, despite folding. Another reason is version control: having a large file means that your commits tend to concentrate on that file. This can potentially lead to a higher quantity of conflicts to be resolved. You also loose the additional log information that your commit modifies specific files (therefore involving specific classes). Instead you see a modification to the module file, with only the commit comment to understand what modification has been done. Summing up, if you prefer the python philosophy, go for the suggestions of the other posts. If you instead prefer the java-like philosophy, create a Nib.py containing class Nib.
1
120
0
I have a module whose purpose is to define a class called "nib". (and a few related classes too.) How should I call the module itself? "nib"? "nibmodule"? Anything else?
Python naming conventions for modules
1
0
0
120,168
712,020
2009-04-02T23:27:00.000
3
1
0
0
python,unit-testing,nose,nosetests
716,408
3
false
0
0
There will be soon: a new --collect switch that produces this behavior was demo'd at PyCon last week. It should be on the trunk "soon" and will be in the 0.11 release. The http://groups.google.com/group/nose-users list is a great resource for nose questions.
1
42
0
I use nosetests to run my unittests and it works well. I want to get a list of all the tests nostests finds without actually running them. Is there a way to do that?
List all Tests Found by Nosetest
0.197375
0
0
9,288
712,113
2009-04-03T00:14:00.000
0
1
0
0
python,escaping,python-module
712,154
1
true
1
0
See lxml, which is based on libxml2. While it's primarily a XML library, HTML support is available.
1
0
0
There is cgi.escape but that appears to be implemented in pure python. It seems like most frameworks like Django also just run some regular expressions. This is something we do a lot, so it would be good to have it be as fast as possible. Maybe C implementations wouldn't be much faster than a series of regexes for this?
Is there a good python module that does HTML encoding/escaping in C?
1.2
0
0
961
712,460
2009-04-03T03:33:00.000
0
0
1
0
python,numeric-ranges
713,040
6
false
0
0
I also had to do something similar for an app lately. If you don't need concrete numbers but just a way to see whether a given number is in the range, you might consider parsing it to a Python expression you can eval into a lambda. For example <3, 5-10, 12 could be func=(lambda x:x<3 or (5 <= x <= 10) or x==12)). Then you can just call the lambda, func(11) to see if 11 belongs in there.
2
6
0
In a Pylons webapp, I need to take a string such as "<3, 45, 46, 48-51, 77" and create a list of ints (which are actually IDs of objects) to search on. Any suggestions on ways to do this? I'm new to Python, and I haven't found anything out there that helps with this kind of thing. The list would be: [1, 2, 3, 45, 46, 48, 49, 50, 51, 77]
Interpreting Number Ranges in Python
0
0
0
5,943
712,460
2009-04-03T03:33:00.000
0
0
1
0
python,numeric-ranges
712,486
6
false
0
0
First, you'll need to figure out what kind of syntax you'll accept. You current have three in your example: Single number: 45, 46 Less than operator Dash ranging: 48-51 After that, it's just a matter of splitting the string into tokens, and checking the format of the token.
2
6
0
In a Pylons webapp, I need to take a string such as "<3, 45, 46, 48-51, 77" and create a list of ints (which are actually IDs of objects) to search on. Any suggestions on ways to do this? I'm new to Python, and I haven't found anything out there that helps with this kind of thing. The list would be: [1, 2, 3, 45, 46, 48, 49, 50, 51, 77]
Interpreting Number Ranges in Python
0
0
0
5,943