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
832,693
2009-05-07T02:57:00.000
1
0
0
0
python,pdf,xhtml,latex
837,011
3
true
1
0
The stand alone program : wkhtmltopdf is exactly what I needed. The PDF rendering of XHTML is the best of seen from a free tool.
1
2
0
I know PDF generation has been discussed a lot here; however, I've yet to find what I need. I'm trying to generate PDF reports (mainly tables) from python. Yes I've tried ReportLab and Pisa. Both had column content "break out" in circumstances I didn't think were unreasonable and unrealistic to encounter in production. When I say reasonable I mean 8 - 12 columns of differing widths. Not 80 - 1200 or some such. I don't need a native python solution as I will be able to have my script launch off the linux command line. I have these reports working in XHTML and they look more or less perfect ... I'd prefer to leverage them. What I'm asking is: does anyone know of a tool I can use that will render tables of arbitrary (again within reason) size in PDF with quality near XHTML browser rendering? I'd like to use something like PrinceXML; however the size of this project doesn't justify the expense of such a tool. As an aside I have tried to do what I need in Latex , something I'm not apposed to but if that is a good idea I'd appreciate an example. Regards, and thanks in advance.
PDF Tables of Arbitrary (within reason) Width
1.2
0
0
600
833,062
2009-05-07T05:52:00.000
0
0
0
1
python,windows-services,tcp
834,878
3
false
0
0
Check to see that the service is running under the Nertwork Service account and not the Local System account. The later doesn't have network access and is the default user to run services under. You can check this by going to the services app under administrative tool in the start menu and looking for your service. If you right-click the service you can go to properties and change the user that it is run under.
2
2
0
I have written a Python TCP/IP server for internal use, using win32serviceutil/py2exe to create a Windows service. I installed it on a computer running Windows XP Pro SP3. However, I can't connect to it when it's running as a service. I can confirm that it's binding to the address/port, because I get a conflict when I try to bind to that address/port with another application. Further, I have checked the Windows Firewall settings and have added appropriate exceptions. If I run the server as a simple console application, everything works as expected. However, when I run it as a service, it doesn't work. I vaguely remember running into this problem before, but for the life of me can't remember any of the details. Suggestions, anyone?
Cannot access Python server running as Windows service
0
0
0
1,004
833,062
2009-05-07T05:52:00.000
1
0
0
1
python,windows-services,tcp
904,114
3
true
0
0
First of all, whenever you implement a Windows service, be sure to add proper logging. My worker threads were terminating because of the exception, "The socket operation could not complete without blocking." The solution was to simply call sock.setblocking(1) after accepting the connection.
2
2
0
I have written a Python TCP/IP server for internal use, using win32serviceutil/py2exe to create a Windows service. I installed it on a computer running Windows XP Pro SP3. However, I can't connect to it when it's running as a service. I can confirm that it's binding to the address/port, because I get a conflict when I try to bind to that address/port with another application. Further, I have checked the Windows Firewall settings and have added appropriate exceptions. If I run the server as a simple console application, everything works as expected. However, when I run it as a service, it doesn't work. I vaguely remember running into this problem before, but for the life of me can't remember any of the details. Suggestions, anyone?
Cannot access Python server running as Windows service
1.2
0
0
1,004
833,063
2009-05-07T05:52:00.000
0
0
1
0
python,c,iterator,jit,algol68
833,074
3
false
0
0
No. Nice and short!
1
6
0
The "yield" statement in python allows simple iteration from a procedure, and it also means that sequences don't need to be pre-calculated AND stored in a array of "arbitrary" size. Is there a there a similar way of iterating (with yield) from a C procedure?
Python style iterators in C
0
0
0
875
833,356
2009-05-07T07:45:00.000
0
0
0
1
python
833,364
2
false
0
0
Set the scheduled task to start the script as minimized.
2
1
0
I have a scheduled task which runs a python script every 10 min so it turns out that a script pops up on my desktop every 10 min how can i make it invincible so my script will work in the background ? I've been told that pythonw will do the work, but I cant figure out how to use it any help ? thanks
How to run a script without being in the tasktray?
0
0
0
109
833,356
2009-05-07T07:45:00.000
3
0
0
1
python
833,391
2
false
0
0
I've been told that pythonw will do the work, but I cant figure out how to use it Normally you just have to rename the file extension to .pyw. Then it will be executed by pythonw.
2
1
0
I have a scheduled task which runs a python script every 10 min so it turns out that a script pops up on my desktop every 10 min how can i make it invincible so my script will work in the background ? I've been told that pythonw will do the work, but I cant figure out how to use it any help ? thanks
How to run a script without being in the tasktray?
0.291313
0
0
109
834,840
2009-05-07T14:05:00.000
3
1
0
0
python,ftp,performance,dos
834,923
7
false
0
0
FTPlib may not be the cleanest Python API, I don't think it so bad that it run ten times slower than a DOS shell script. Unless you do not provide any code to compare, e.g you shell and you python snippet to batch dl 5000 files, I can't see how we can help you.
2
4
0
I have been playing around with Python's FTP library and am starting to think that it is too slow as compared to using a script file in DOS? I run sessions where I download thousands of data files (I think I have over 8 million right now). My observation is that the download process seems to take five to ten times as long in Python than it does as compared to using the ftp commands in the DOS shell. Since I don't want anyone to fix my code I have not included any. I am more interested in understanding if my observation is valid or if I need to tinker more with the arguments.
Python's FTPLib too slow?
0.085505
0
0
8,009
834,840
2009-05-07T14:05:00.000
4
1
0
0
python,ftp,performance,dos
835,474
7
false
0
0
The speed problem is probably in your code. FTPlib is not 10 times slower.
2
4
0
I have been playing around with Python's FTP library and am starting to think that it is too slow as compared to using a script file in DOS? I run sessions where I download thousands of data files (I think I have over 8 million right now). My observation is that the download process seems to take five to ten times as long in Python than it does as compared to using the ftp commands in the DOS shell. Since I don't want anyone to fix my code I have not included any. I am more interested in understanding if my observation is valid or if I need to tinker more with the arguments.
Python's FTPLib too slow?
0.113791
0
0
8,009
834,932
2009-05-07T14:22:00.000
1
1
0
0
java,python,authentication,encryption,hash
840,803
4
false
1
0
Let me just add a few random thoughts/comments to your proposals. RSA: Since you are mainly interested in authentication, I assume you'd want to use RSA signatures. This would imply that each user needs his own privat key. To me that sounds a little bit like overkill, especially when user and server already share common secrets (i.e., passwords). Using SHA256 is a good approach. I have some problems to understand why you include a salt, since a salt is commonly use to avoid that an attacker precomputes hashes of dictionaries. To be clear: dicitionary attacks are a problem here. An attacker could try to hash messages with all passwords from a dictionary. Just he has to reapeat this attack for each user and can't reuse precomputed values. One way to make such an attack a little more difficult is called key strengthening, e.g. by reapeatedly hashing the result n times and hence forcing an attacker to perform more work during a dictionary attack. I completely agree that HMAC is better than just SHA-256. After all HMAC was designed for authentication. I'm not sure why you want to hash the message before computing the HMAC. HMAC does that for you. Encryption does not always provide authentication. This is specially in cases when the attacker learns the plaintext, as he does in your case. He might be able to exploit properties of the encryption mode to manipulate the ciphertext an know exactly how the resulting plaintext will look like (E.g. the CBC mode allows these kind of manipulations). Your previous proposal (HMAC) is preferable. Finally, if you can setup an SSL connection between user and server, as others suggest: this would be a much safer solution, since not even the dicionary attack mentioned above would be possible.
3
0
0
I am writing a server-client application to receive user message and publish it. Thinking about authentication method. Asymmetric encryption, probably RSA. Hash (salt+password+'msg'+'userid'), SHA256 HMAC, SHA256. seems to be more secured than the method 2. Also involve hashing the password and msg data. Symmetric Encryption of the 'msg' with static password stored on both sides, probably AES. There is no need for encryption as the msg would be publish online anyway. So I am more lean to the HMAC or PKI method. I'm using java to send the request (including whatever authentication method to be implemented) www.mysite.com/foo?userid=12345&msg=hello&token=abc1234 python on the server side to receive request and make sure the request is from the valid user. The problems are in integration and make sure both sides understand each other's authentication token. It is a big factor for me. And the availability of the libraries available on both language are taken into account as well. Or I can choose to rewrite the server side into java. (Why not python? The client side application need to be in java) What do you think? EDIT: I would not treat this as a web application. The application does not serve any webpage. Most of the operations are not related to the web. Just the client-server communication go through internet. And sending POST/GET via HTTP is what I thought of as the simpler albeit insecure way to do it. Feel free to suggest me any other alternative. SSL is a secure way for encryption. But it does not prevent attacker from sending message to the server impose as the user. Anyone can initiate a HTTPS connection. And the content of the communication does not need to be encrypted. It will be published online by the server anyway. What I need is a way to authenticate the message and sender. For now I am lean to HMAC algorithm. RSA would be more secure but it comes with more developer efforts as well. Will see how it goes. Thank you.
authentication method
0.049958
0
0
1,626
834,932
2009-05-07T14:22:00.000
2
1
0
0
java,python,authentication,encryption,hash
836,074
4
false
1
0
Can't you just use standard SSL sockets to secure the connection, validate the user with a password, and then send the message to be published? If there won't be many clients, you can even use a self-signed certificate and put it in a KeyStore in the client app, that way you won't need to buy a certificate from Verisign or anyone else. If you are storing the user's password hash on the server (as I think you should otherwise how are you going to validate the user's password), then you can first reproduce that hash on the client side (let's assume you hash user+pass) and then append that to the message and hash the result. You send the user id, hash and message to the server. On the server side you receive a request with a user id, you retrieve the user's password (the server only has stored the hash of user+pass), you append that to the message and hash it again, and compare it against the hash in the request. If it matches, the user can publish the message. Oh and you should use HTTP POST, instead of sending data on the URL. The server should not accept data on the URL for the publish request.
3
0
0
I am writing a server-client application to receive user message and publish it. Thinking about authentication method. Asymmetric encryption, probably RSA. Hash (salt+password+'msg'+'userid'), SHA256 HMAC, SHA256. seems to be more secured than the method 2. Also involve hashing the password and msg data. Symmetric Encryption of the 'msg' with static password stored on both sides, probably AES. There is no need for encryption as the msg would be publish online anyway. So I am more lean to the HMAC or PKI method. I'm using java to send the request (including whatever authentication method to be implemented) www.mysite.com/foo?userid=12345&msg=hello&token=abc1234 python on the server side to receive request and make sure the request is from the valid user. The problems are in integration and make sure both sides understand each other's authentication token. It is a big factor for me. And the availability of the libraries available on both language are taken into account as well. Or I can choose to rewrite the server side into java. (Why not python? The client side application need to be in java) What do you think? EDIT: I would not treat this as a web application. The application does not serve any webpage. Most of the operations are not related to the web. Just the client-server communication go through internet. And sending POST/GET via HTTP is what I thought of as the simpler albeit insecure way to do it. Feel free to suggest me any other alternative. SSL is a secure way for encryption. But it does not prevent attacker from sending message to the server impose as the user. Anyone can initiate a HTTPS connection. And the content of the communication does not need to be encrypted. It will be published online by the server anyway. What I need is a way to authenticate the message and sender. For now I am lean to HMAC algorithm. RSA would be more secure but it comes with more developer efforts as well. Will see how it goes. Thank you.
authentication method
0.099668
0
0
1,626
834,932
2009-05-07T14:22:00.000
0
1
0
0
java,python,authentication,encryption,hash
837,532
4
false
1
0
RSA protocol is generally used to setup a key exchange for a faster encryption means. That's how SSL works. If the security requirements for your applications are so sensitive that you require PKI, then it should be said (without any intent to be harsh) that if you need to ask about it on SO, then its probably something you shouldn't attempt to do (given that generally successful attacks on secure channels attack weakpoints of the implementation). As Chochos has suggested, what's wrong with simply using the existing SSL infrastructure in Java and your server to set up a secure https connection and then simply pass the user password from client to the server?
3
0
0
I am writing a server-client application to receive user message and publish it. Thinking about authentication method. Asymmetric encryption, probably RSA. Hash (salt+password+'msg'+'userid'), SHA256 HMAC, SHA256. seems to be more secured than the method 2. Also involve hashing the password and msg data. Symmetric Encryption of the 'msg' with static password stored on both sides, probably AES. There is no need for encryption as the msg would be publish online anyway. So I am more lean to the HMAC or PKI method. I'm using java to send the request (including whatever authentication method to be implemented) www.mysite.com/foo?userid=12345&msg=hello&token=abc1234 python on the server side to receive request and make sure the request is from the valid user. The problems are in integration and make sure both sides understand each other's authentication token. It is a big factor for me. And the availability of the libraries available on both language are taken into account as well. Or I can choose to rewrite the server side into java. (Why not python? The client side application need to be in java) What do you think? EDIT: I would not treat this as a web application. The application does not serve any webpage. Most of the operations are not related to the web. Just the client-server communication go through internet. And sending POST/GET via HTTP is what I thought of as the simpler albeit insecure way to do it. Feel free to suggest me any other alternative. SSL is a secure way for encryption. But it does not prevent attacker from sending message to the server impose as the user. Anyone can initiate a HTTPS connection. And the content of the communication does not need to be encrypted. It will be published online by the server anyway. What I need is a way to authenticate the message and sender. For now I am lean to HMAC algorithm. RSA would be more secure but it comes with more developer efforts as well. Will see how it goes. Thank you.
authentication method
0
0
0
1,626
836,992
2009-05-07T20:55:00.000
0
0
0
1
python,google-app-engine,transactions,google-cloud-datastore
838,960
3
true
1
0
After a through research, I have found that a distributed transaction layer that provides a solution to the single entity group restriction has been developed in userland with the help of some google people. But so far, it is not released and is only available in java.
1
3
0
in my google app application, whenever a user purchases a number of contracts, these events are executed (simplified for clarity): user.cash is decreased user.contracts is increased by the number contracts.current_price is updated. market.no_of_transactions is increased by 1. in a rdms, these would be placed within the same transaction. I conceive that google datastore does not allow entities of more than one model to be in the same transaction. what is the correct approach to this issue? how can I ensure that if a write fails, all preceding writes are rolled back? edit: I have obviously missed entity groups. Now I'd appreciate some further information regarding how they are used. Another point to clarify is google says "Only use entity groups when they are needed for transactions. For other relationships between entities, use ReferenceProperty properties and Key values, which can be used in queries". does it mean I have to define both a reference property (since I need queriying them) and a parent-child relationship (for transactions)? edit 2: and finally, how do I define two parents for an entity if the entity is being created to establish an n-to-n relationship between 2 parents?
datastore transaction restrictions
1.2
1
0
384
837,256
2009-05-07T21:59:00.000
-1
1
0
1
python,ruby
837,862
5
false
1
0
For python code to run the interpreter needs to be launched as a process. So system() is your best option. For calling the python code you could use RPC or network sockets, got for the simplest thing which could possibly work.
2
5
0
Does a easy to use Ruby to Python bridge exist? Or am I better off using system()?
How do I invoke Python code from Ruby?
-0.039979
0
0
6,499
837,256
2009-05-07T21:59:00.000
2
1
0
1
python,ruby
837,296
5
false
1
0
I don't think there's any way to invoke Python from Ruby without forking a process, via system() or something. The language run times are utterly diferent, they'd need to be in separate processes anyway.
2
5
0
Does a easy to use Ruby to Python bridge exist? Or am I better off using system()?
How do I invoke Python code from Ruby?
0.07983
0
0
6,499
839,384
2009-05-08T11:20:00.000
1
0
0
1
python,twisted,protocols,p2p
839,411
4
false
0
0
Yes, twisted was used to create the initial version of Bittorrent. There are some opensource libraries to start from.
1
14
0
Can you tell me: could I use twisted for p2p-applications creating? And what protocols should I choose for this?
Twisted and p2p applications
0.049958
0
0
5,823
839,755
2009-05-08T13:19:00.000
4
0
1
0
python,time,python-2.5,time-t,year2038
1,865,730
3
true
0
0
The best solution I've found is to get a source copy of Python 2.5, and re-compile the time module with compilers which defaults time_t to 64 bit, for example VS2005 or VS2008 (may also configure the C runtime to prevent side-by-side issue).
3
5
0
The official Python 2.5 on Windows was build with Visual Studio.Net 2003, which uses 32 bit time_t. So when the year is > 2038, it just gives exceptions. Although this is fixed in Python 2.6 (which changed time_t to 64 bit with VS2008), I'd like to use 2.5 because many modules are already compiled for it. So here's my question - is there any solution to easily let my program handle year > 2038 and still using official Python 2.5? For example some pre-made libraries like "time64" or "longtime" etc... Please do not tell me to upgrade to 2.6+ or forget about the bug - I have my reason to need to make it work, that's why I post the question here.
How to use time > year 2038 on official Windows Python 2.5
1.2
0
0
2,919
839,755
2009-05-08T13:19:00.000
7
0
1
0
python,time,python-2.5,time-t,year2038
839,830
3
false
0
0
I don't mean to sound trite, but why not: forget about the Y2038 bug with Python 2.5 upgrade to Python 2.6 at some point in the future before 2038 edit: To clarify: (and I'm serious — I didn't mean to poke fun) Presumably you can upgrade Python to 2.6 (or later) at some indefinite time between now and 2038. Maybe in 2012. Maybe in 2015. Maybe in 2037. If you are aware of the differences between the Python timestamp variable in your application (I'm not much of a Python user), it seems like these would be the important aspects to consider: what data is being saved persistently how a Python 2.5 timestamp variable that has been persisted, gets restored using Python 2.6 (presumably it will "do the right thing") whether old data will be stored in its persistent form long enough for ambiguities to arise (e.g. the year "96" is unambiguous when considered between 1950 and 2049, but if that data is kept around until the year 2230 then "96" could be 1996, 2096, or 2196) If the answers are favorable, just use the regular timestamp with its 2038 bug. You'll have to compare that with the amount of redesign/refactoring you'd have to do to make your application work with an alternate timestamp (e.g. a database timestamp string or whatever).
3
5
0
The official Python 2.5 on Windows was build with Visual Studio.Net 2003, which uses 32 bit time_t. So when the year is > 2038, it just gives exceptions. Although this is fixed in Python 2.6 (which changed time_t to 64 bit with VS2008), I'd like to use 2.5 because many modules are already compiled for it. So here's my question - is there any solution to easily let my program handle year > 2038 and still using official Python 2.5? For example some pre-made libraries like "time64" or "longtime" etc... Please do not tell me to upgrade to 2.6+ or forget about the bug - I have my reason to need to make it work, that's why I post the question here.
How to use time > year 2038 on official Windows Python 2.5
1
0
0
2,919
839,755
2009-05-08T13:19:00.000
7
0
1
0
python,time,python-2.5,time-t,year2038
839,826
3
false
0
0
The datetime module in the standard library should work fine for you. What do you need from module time that datetime doesn't offer?
3
5
0
The official Python 2.5 on Windows was build with Visual Studio.Net 2003, which uses 32 bit time_t. So when the year is > 2038, it just gives exceptions. Although this is fixed in Python 2.6 (which changed time_t to 64 bit with VS2008), I'd like to use 2.5 because many modules are already compiled for it. So here's my question - is there any solution to easily let my program handle year > 2038 and still using official Python 2.5? For example some pre-made libraries like "time64" or "longtime" etc... Please do not tell me to upgrade to 2.6+ or forget about the bug - I have my reason to need to make it work, that's why I post the question here.
How to use time > year 2038 on official Windows Python 2.5
1
0
0
2,919
841,159
2009-05-08T18:23:00.000
0
0
1
0
python,yacc,lex,ply
842,331
4
false
0
0
I typically use a separate 'command reader' to obtain a complete command - probably a line in your case - into a host variable string, and then arrange for the lexical analyzer to analyze the string, including telling me when it didn't reach the end. This is hard to set up, but make some classes of error reporting easier. One of the places I've used this technique routinely has multi-line commands with 3 comment conventions, two sets of quoted strings, and some other nasties to set my teeth on edge (context sensitive tokenization - yuck!). Otherwise, Don's advice with the Yacc 'error' token is good.
2
3
0
Forgive me, I'm completely new to parsing and lex/yacc, and I'm probably in way over my head, but nonetheless: I'm writing a pretty basic calculator with PLY, but it's input might not always be an equation, and I need to determine if it is or not when parsing. The extremes of the input would be something that evaluates perfectly to an equation, which it parses fine and calculates, or something that is nothing like an equation, which fails parsing and is also fine. The gray area is an input that has equation-like parts, of which the parser will grab and work out. This isn't what I want - I need to be able to tell if parts of the string didn't get picked up and tokenized so I can throw back an error, but I have no idea how to do this. Does anyone know how I can define, basically, a 'catch anything that's left' token? Or is there a better way I can handle this?
Tokenizing left over data with lex/yacc
0
0
0
674
841,159
2009-05-08T18:23:00.000
1
0
1
0
python,yacc,lex,ply
842,248
4
true
0
0
There is a built-in error token in yacc. You would normally do something like: line: goodline | badline ; badline : error '\n' /* Error-handling action, if needed */ goodline : equation '\n' ; Any line that doesn't match equation will be handled by badline. You might want to use yyerrok in the error handling action to ensure error processing is reset for the next line.
2
3
0
Forgive me, I'm completely new to parsing and lex/yacc, and I'm probably in way over my head, but nonetheless: I'm writing a pretty basic calculator with PLY, but it's input might not always be an equation, and I need to determine if it is or not when parsing. The extremes of the input would be something that evaluates perfectly to an equation, which it parses fine and calculates, or something that is nothing like an equation, which fails parsing and is also fine. The gray area is an input that has equation-like parts, of which the parser will grab and work out. This isn't what I want - I need to be able to tell if parts of the string didn't get picked up and tokenized so I can throw back an error, but I have no idea how to do this. Does anyone know how I can define, basically, a 'catch anything that's left' token? Or is there a better way I can handle this?
Tokenizing left over data with lex/yacc
1.2
0
0
674
841,669
2009-05-08T20:35:00.000
8
1
0
1
.net,ruby,powershell,scripting,ironpython
841,689
7
false
0
0
Except for the seventh item on your list this should be fairly trivial using Powershell and WMI, as this is perhaps the natural domain for Powershell. Since you won't need another language for the first six list items it shouldn't really matter what you use for the last one. You probably can use PS (I've never done IO with it, though) or whatever suits you. As for your second question: VBScript is probably not going to go away in the near future as the Windows Script Host is still a safer bet when writing small scripts for deployment, as it comes preinstalled on every Windows since 98. Powershell is only included in Windows 7 and later. That being said, Powershell is surely targeted at obsoleting WSH and CMD for automation purposes since it offers the same features of the aforementioned ones and much more (like easy .NET and WMI access). VB.NET on the other hand is one of the primary .NET languages marketed by Microsoft. It has little to no relation to VBScript, is no competitor to Powershell or WPF (heck, those are completely different technologies). You may see some convergence with C# going on as both languages still seem to struggle a little finding their intended market. Still, VB.NET is the easiest choice of switching to .NET when you're a VB programmer and there were/are lots of them MS didn't want to lose just because they created .NET.
3
0
0
I just got a project where I have to do the following on a Windows OS: detect how many drives (C: D: E: ..etc) are connected to current system what the system labels are for each volume how much storage (both used and free) for each of the drives what format each drive is (NTFS/FAT32) how many files are in a given directory in any of those drives how big each file size is File processing (each file is about 2GB) where I have to do a lot of C-like fseek(), and binary data parsing, and big to little-endian conversion. Have to write some logic code as well. I'm an experienced C\C++ programmer, but I thought this would be a perfect time for me to start learning about scripting. Candidates that I thought of are: ( Python || Ruby ) && PowerShell. Are those the kinds of things I can accomplish with, say, IronPython+Powershell? Or are there better tools/languages out there? PS: Is PowerShell meant to replace VBScript? Also, what is VB.net good for anyway now that C#, WPF, and Powershell exist?
Advice for Windows system scripting+programming
1
0
0
501
841,669
2009-05-08T20:35:00.000
0
1
0
1
.net,ruby,powershell,scripting,ironpython
844,915
7
false
0
0
As for Perl, Ruby too has access to all Win32 API and WMI functions.
3
0
0
I just got a project where I have to do the following on a Windows OS: detect how many drives (C: D: E: ..etc) are connected to current system what the system labels are for each volume how much storage (both used and free) for each of the drives what format each drive is (NTFS/FAT32) how many files are in a given directory in any of those drives how big each file size is File processing (each file is about 2GB) where I have to do a lot of C-like fseek(), and binary data parsing, and big to little-endian conversion. Have to write some logic code as well. I'm an experienced C\C++ programmer, but I thought this would be a perfect time for me to start learning about scripting. Candidates that I thought of are: ( Python || Ruby ) && PowerShell. Are those the kinds of things I can accomplish with, say, IronPython+Powershell? Or are there better tools/languages out there? PS: Is PowerShell meant to replace VBScript? Also, what is VB.net good for anyway now that C#, WPF, and Powershell exist?
Advice for Windows system scripting+programming
0
0
0
501
841,669
2009-05-08T20:35:00.000
0
1
0
1
.net,ruby,powershell,scripting,ironpython
842,535
7
false
0
0
I'll give you the unpopular answer then since no one else has added it: Perl. If you're comfortable with the Win32 API as a C/C++ programmer, Perl may be the easier way to go. It has modules for accessing the Win32 API and Perl is quite easy for C/C++ programmers to get up to speed in. Perl has always done the job for me in the past.
3
0
0
I just got a project where I have to do the following on a Windows OS: detect how many drives (C: D: E: ..etc) are connected to current system what the system labels are for each volume how much storage (both used and free) for each of the drives what format each drive is (NTFS/FAT32) how many files are in a given directory in any of those drives how big each file size is File processing (each file is about 2GB) where I have to do a lot of C-like fseek(), and binary data parsing, and big to little-endian conversion. Have to write some logic code as well. I'm an experienced C\C++ programmer, but I thought this would be a perfect time for me to start learning about scripting. Candidates that I thought of are: ( Python || Ruby ) && PowerShell. Are those the kinds of things I can accomplish with, say, IronPython+Powershell? Or are there better tools/languages out there? PS: Is PowerShell meant to replace VBScript? Also, what is VB.net good for anyway now that C#, WPF, and Powershell exist?
Advice for Windows system scripting+programming
0
0
0
501
842,120
2009-05-08T22:41:00.000
1
0
0
1
python,windows,scripting,batch-file,io
842,139
3
false
0
0
Try subprocess.Popen(). It allows you to redirect stdout and stderr to files.
1
3
0
I'm trying to write a python script (in windows) that runs a batch file and will take the command line output of that batch file as input. The batch file runs processes that I don't have access to and gives output based on whether those processes are successful. I'd like to take those messages from the batch file and use them in the python script. Anyone have any ideas on how to do this ?
Piping Batch File output to a Python script
0.066568
0
0
9,251
842,208
2009-05-08T23:10:00.000
20
0
0
0
wxpython,wxwidgets
843,023
1
false
0
1
wx.Window is the base class for all widgets (not necessarily all windows - the name is misleading). wx.Panel is a subclass of wx.Window, which is more tailored towards containing widgets inside it. For example, it by default allows moving between widgets using "tab", and handles a focus event in a way that is more useful with child widgets.
1
4
0
I got the impression that Panel is better. Is that true? What advantage does one have over the other? What reason is there to use one over the other?
wxPython: What is the difference between a wx.Panel and a wx.Window?
1
0
0
3,627
842,831
2009-05-09T06:45:00.000
4
0
0
0
python,sql-server,django,pyodbc
843,500
7
false
1
0
We are using django-mssql in production at our company. We too had an existing system using mssql. For me personally it was the best design decision I have ever made because my productivity increased dramatically now that I can use django . I submitted a patch but when I started using django-mssql and did a week or two of testing.Since then (October 2008) we run our system on django and it runs solid. I also tried pyodbc but I did not like to much. We are running a repair system where all transactions run through this system 40 heavy users. If you have more questions let me know.
2
52
0
Has anybody got recent experience with deploying a Django application with an SQL Server database back end? Our workplace is heavily invested in SQL Server and will not support Django if there isn't a sufficiently developed back end for it. I'm aware of mssql.django-pyodbc and django-mssql as unofficially supported back ends. Both projects seem to have only one person contributing which is a bit of a worry though the contributions seem to be somewhat regular. Are there any other back ends for SQL Server that are well supported? Are the two I mentioned here 'good enough' for production? What are your experiences?
Using Sql Server with Django in production
0.113791
1
0
48,333
842,831
2009-05-09T06:45:00.000
1
0
0
0
python,sql-server,django,pyodbc
843,476
7
false
1
0
Haven't used it in production yet, but my initial experiences with django-mssql have been pretty solid. All you need are the Python Win32 extensions and to get the sqlserver_ado module onto your Python path. From there, you just use sql_server.pyodbc as your DATABASE_ENGINE. So far I haven't noticed anything missing, but I haven't fully banged on it yet either.
2
52
0
Has anybody got recent experience with deploying a Django application with an SQL Server database back end? Our workplace is heavily invested in SQL Server and will not support Django if there isn't a sufficiently developed back end for it. I'm aware of mssql.django-pyodbc and django-mssql as unofficially supported back ends. Both projects seem to have only one person contributing which is a bit of a worry though the contributions seem to be somewhat regular. Are there any other back ends for SQL Server that are well supported? Are the two I mentioned here 'good enough' for production? What are your experiences?
Using Sql Server with Django in production
0.028564
1
0
48,333
842,856
2009-05-09T07:20:00.000
0
0
1
0
python,regex,string,substring
842,904
6
false
0
0
First of all, I would suggest you to sort the initial list in ascending order. Because scanning for a shorter substring is faster that scanning for a longer substring.
1
30
0
I have a list of possible substrings, e.g. ['cat', 'fish', 'dog']. In practice, the list contains hundreds of entries. I'm processing a string, and what I'm looking for is to find the index of the first appearance of any of these substrings. To clarify, for '012cat' the result is 3, and for '0123dog789cat' the result is 4. I also need to know which substring was found (e.g. its index in the substring list or the text itself), or at least the length of the substring matched. There are obvious brute-force ways to achieve this, I wondered if there's any elegant Python/regex solution for this.
What's the most efficient way to find one of several substrings in Python?
0
0
0
14,288
843,268
2009-05-09T13:05:00.000
0
0
1
0
python,windows
843,294
4
false
0
0
I think you must use windows API, and run by python. use os.system('logoff'); (or logout, I forget) it is not tested, because I am using ubuntu now...
1
1
0
I want to write a small program that given a time (in minutes) as input, sleeps in the background for that time, and then forces a return to the "switch user screen" (equivalent to the Winkey+L combination) or logs off a user (may be another user logged in on the same machine). What functions or libraries in Python could I use for this? Edit: I prefer just a return to the "Switch User" screen rather than actually logging off Perhaps there's a simple Windows command to do this, which I could use I have Windows XP if that's relevant
Logout or switch user in Windows using Python
0
0
0
3,173
843,698
2009-05-09T17:22:00.000
3
0
1
0
python,objective-c,macos,pyobjc
845,560
3
true
0
0
Finally figured this one out myself. The key to this is to make the final executable link with /System/Library/Frameworks/Python.framework instead of /Library/Frameworks/Python.framework.
1
1
0
I use Python 2.6 more than I use Leopard's default python installation, so I have it set as my main Python installation. But I'd rather use the default Python for a PyObjC program I'm working on. Is there any way to specify to only use it instead of Python 2.6?
How do I choose which Python installation to run in a PyObjC program?
1.2
0
0
454
844,746
2009-05-10T05:15:00.000
2
0
0
0
python,django,django-templates
844,828
6
false
1
0
I ended up adding a method to the model in question, and that method can be accessed like an attribute in the template. Still, i think it would be great if a built in tag allowed you to dynamically lookup an attribute, since this is a problem a lot of us constantly have in our templates.
1
50
0
Python's getattr() method is useful when you don't know the name of a certain attribute in advance. This functionality would also come in handy in templates, but I've never figured out a way to do it. Is there a built-in tag or non-built-in tag that can perform dynamic attribute lookups?
Performing a getattr() style lookup in a django template
0.066568
0
0
25,291
845,502
2009-05-10T15:11:00.000
8
1
1
0
c#,python,ironpython
845,506
3
false
0
0
Yes, by hosting IronPython.
1
6
0
Is there an easy way to call Python objects from C#, that is without any COM mess?
using Python objects in C#
1
0
0
10,077
846,139
2009-05-10T21:25:00.000
3
1
1
0
python,ruby
846,168
4
false
0
0
After running through some tutorials on-line (the ones posted so far look pretty good), find a current Ruby project you've done (or are working on) and re-write it in Python. I've used this technique to transition from various languages, and it's helped enormously.
1
17
0
I've been programming Ruby pretty extensively for the past four years or so, and I'm extremely comfortable with the language. For no particular reason, I've decided to learn some Python this week. Is there a specific book, tutorial, or reference that would be well-suited to someone coming from a nearly-identical language, or should I just "Dive into Python"? Thanks!
What's the quickest way for a Ruby programmer to pick up Python?
0.148885
0
0
4,331
846,383
2009-05-11T00:41:00.000
11
0
0
0
python,database,django,macos
846,403
3
true
0
0
This is an error that crops up when the build tools cannot find your Postgresql libraries. It means one of three things: You don't have postgresql installed on your system. If so, download and build postgres, or download a pre-built psycopg2 binary for OS X. You have postgresql installed on your system, but you installed from a binary package and therefore don't have the necessary libraries that psycopg2 needs. In this case, download and build postgres. More commonly, though, this means that you have built postgres on your system and just need to instruct psycopg2 how to find the pg_config binary so that it can configure the compilation. Either: a. put the path to pg_config in your shell path (it's usually at /usr/local/pgsql/bin/ if you built postgres from source using the defaults. b. or, edit the setup.cfg file in the psycopg2 source folder and provide the full path to pg_config on the line that starts with pg_config=. Be sure to uncomment this line by removing the hash symbol at the front. If you built postgres using the defaults, the line will look something like: pg_config=/usr/local/pgsql/bin/pg_config
1
3
0
I have downloaded the latest build of pyscopg2 and have tried to build and install it using the directions provided. However i always get an error saying that 'w' is undeclared. Does anybody have any experience with this?
Problem installing pyscopg2 on Mac OS X
1.2
0
0
6,020
846,950
2009-05-11T06:30:00.000
0
0
0
1
python,networking,sockets,twisted,httplib2
847,014
2
true
0
0
Should new networking code (with the exception of small command line tools) be written with Twisted? Maybe. It really depends. Sometimes its just easy enough to wrap the blocking calls in their own thread. Twisted is good for large scale network code. Would you mix Twisted, http2lib or socket code in the same project? Sure. But just remember that Twisted is single threaded, and that any blocking call in Twisted will block the entire engine. Is Twisted pythonic for most libraries (it is more complex than alternatives, introduce a dependency to a non-standard package...)? There are many Twisted zealots that will say it belongs in the Python standard library. But many people can implement decent networking code with asyncore/asynchat.
1
6
0
Many python libraries, even recently written ones, use httplib2 or the socket interface to perform networking tasks. Those are obviously easier to code on than Twisted due to their blocking nature, but I think this is a drawback when integrating them with other code, especially GUI one. If you want scalability, concurrency or GUI integration while avoiding multithreading, Twisted is then a natural choice. So I would be interested in opinions in those matters: Should new networking code (with the exception of small command line tools) be written with Twisted? Would you mix Twisted, http2lib or socket code in the same project? Is Twisted pythonic for most libraries (it is more complex than alternatives, introduce a dependency to a non-standard package...)? Edit: please let me phrase this in another way. Do you feel writing new library code with Twisted may add a barrier to its adoption? Twisted has obvious benefits (especially portability and scalability as stated by gimel), but the fact that it is not a core python library may be considered by some as a drawback.
Is Twisted an httplib2/socket replacement?
1.2
0
1
1,969
847,860
2009-05-11T12:24:00.000
1
0
0
0
c#,c++,python,c,vb.net
847,883
2
false
0
1
Compiling can be done by calling cl.exe which comes with Visual Studio. Of course you could also use GCC instead.
1
1
0
I'm trying to make a vb.net application that has got 2 textboxes, 7 radio buttons and 2 buttons(one named compile and the other 'run'). How can I load the content of a C/C++(or any programming language) file into the 1st textbox and on clicking the compile button, i should be able to show the errors or the C/C++ program in the 2nd textbox. On clicking Run, I should be able to show the output in the 2nd textbox. In short, I want to use the 2nd textbox as a terminal/console. The radio buttons are 4 selecting the language C or C++ or python or C# or java or perl or vb. Are the compilers of all these languages present in .net? If so how can I call them?
How to write a vb.net code to compile C/C++ programs?
0.099668
0
0
1,053
848,508
2009-05-11T14:55:00.000
0
1
0
1
python,m2crypto
848,795
3
false
0
0
Possibly its looking up shared libs libssl.so and libcrypto.so and finding the old ones in /usr/lib if you add the new_path to the top of /etc/ld.so.conf so it gets searched first it would work. But this might break other OpenSSL applications expecting old OpenSSL.
1
2
0
M2Crypto provides EC support for ECDSA/ECDH. I have installed OpenSSL 0.9.8i which contains support for EC. However when I run "from M2Crypto import EC,BIO" I get error saying EC_init() failed. So I added debug to print m2.OPENSSL_VERSION_TEXT value. It gets printed as "OpenSSL 0.9.7 19 Feb 2003". This version of OpenSSL doesnot support EC. I tried "python setup.py build build_ext --openssl="new_path where OpenSSL 0.9.8i is installed". Though M2Crypto is built again "Python setup.py install" , I still see that it points to "Old version of OpenSSL". Any Pointers on how to successfully get M2Crypto to use 0.9.8i will be useful.
Python M2Crypto EC Support
0
0
0
880
849,334
2009-05-11T18:13:00.000
2
0
1
0
python,resources,location,package,shared
849,803
3
false
0
0
We put non .py files in /opt/foo/foo-1.2/... Except, of course, for static media that is served by Apache, that goes to /var/www/html/foo/foo-1.1/media/... Except, of course, for customer-specific configuration files. They go to /var/opt/customer/foo/... Those follow the Linux standards as I understand them. We try to stay away from /usr/lib/ and /lib kinds of locations because those feel like they're part of the distribution. We lean toward /opt and /var because they're clearly separated from the linux distro directories.
2
4
0
This should be a common scenario, but could not find any relevant post yet.. I plan to deploy a Python library (I guess the same applies to regular applications) which makes use of some images and other resource files. What is the standard location for such items? I imagine, for project Foo, the choices would be Have resources directory in the source repository and then move files to /usr/share/foo/ Place resources directly inside the python package that goes under /usr/lib/python-<version>/foo/ Any suggestions? Edit: As suggested, clarifying that the main platform this will be running on is Linux.
Standard non-code resource location for python packages
0.132549
0
0
453
849,334
2009-05-11T18:13:00.000
2
0
1
0
python,resources,location,package,shared
849,446
3
true
0
0
This question is somewhat incomplete, because a proper answer would depend on the underlying operating system, as each has its own modus operandi. In linux (and most unix based OSs) for example /usr/share/foo or /usr/local/share/foo would be the standard. In OS X you can do the same, but I would think "/Library/Application Support/Foo" (although that's usually for storing settings and whatnot) would be the place to put such things, though if you're writing libraries following the "Framework" idea, all the resources would be included in the /Library/Frameworks/Foo.Framework" ... Apps on OS X on the other hand should keeps all there resources within the Resources directory inside Foo.app
2
4
0
This should be a common scenario, but could not find any relevant post yet.. I plan to deploy a Python library (I guess the same applies to regular applications) which makes use of some images and other resource files. What is the standard location for such items? I imagine, for project Foo, the choices would be Have resources directory in the source repository and then move files to /usr/share/foo/ Place resources directly inside the python package that goes under /usr/lib/python-<version>/foo/ Any suggestions? Edit: As suggested, clarifying that the main platform this will be running on is Linux.
Standard non-code resource location for python packages
1.2
0
0
453
850,630
2009-05-12T00:18:00.000
3
1
1
0
python,embedded
850,642
5
false
0
0
Number 3 should and will work. You do not need the .pyo or .py files in order to use the compiled python code.
2
12
0
To squeeze into the limited amount of filesystem storage available in an embedded system I'm currently playing with, I would like to eliminate any files that could reasonably be removed without significantly impacting functionality or performance. The *.py, *.pyo, and *.pyc files in the Python library account for a sizable amount of space, I'm wondering which of these options would be most reasonable for a Python 2.6 installation in a small embedded system: Keep *.py, eliminate *.pyc and *.pyo (Maintain ability to debug, performance suffers?) Keep *.py and *.pyc, eliminate *.pyo (Does optimization really buy anything?) Keep *.pyc, eliminate *.pyo and *.py (Will this work?) Keep *.py, *.pyc, and *.pyo (All are needed?)
Python *.py, *.pyo, *.pyc: Which can be eliminated for an Embedded System?
0.119427
0
0
7,405
850,630
2009-05-12T00:18:00.000
2
1
1
0
python,embedded
851,194
5
false
0
0
I would recommend keeping only .py files. The difference in startup time isn't that great, and having the source around is a plus, as it will run under different python versions without any issues. As of python 2.6, setting sys.dont_write_bytecode to True will suppress compilation of .pyc and .pyo files altogether, so you may want to use that option if you have 2.6 available.
2
12
0
To squeeze into the limited amount of filesystem storage available in an embedded system I'm currently playing with, I would like to eliminate any files that could reasonably be removed without significantly impacting functionality or performance. The *.py, *.pyo, and *.pyc files in the Python library account for a sizable amount of space, I'm wondering which of these options would be most reasonable for a Python 2.6 installation in a small embedded system: Keep *.py, eliminate *.pyc and *.pyo (Maintain ability to debug, performance suffers?) Keep *.py and *.pyc, eliminate *.pyo (Does optimization really buy anything?) Keep *.pyc, eliminate *.pyo and *.py (Will this work?) Keep *.py, *.pyc, and *.pyo (All are needed?)
Python *.py, *.pyo, *.pyc: Which can be eliminated for an Embedded System?
0.07983
0
0
7,405
850,877
2009-05-12T02:20:00.000
-1
0
1
0
python,algorithm,for-loop
850,910
5
false
0
0
For a general list, you have to at least go over every member at least once to get the sum, which is exactly what a for loop does. Using library APIs (like sum) is more convenient, but I doubt it would actually be faster.
2
13
0
Is there a way to sum up a list of numbers faster than with a for-loop, perhaps in the Python library? Or is that something really only multi-threading / vector processing can do efficiently? Edit: Just to clarify, it could be a list of any numbers, unsorted, just input from the user.
Faster way to sum a list of numbers than with a for-loop?
-0.039979
0
0
27,803
850,877
2009-05-12T02:20:00.000
1
0
1
0
python,algorithm,for-loop
850,898
5
false
0
0
Well, I don't know if it is faster but you could try a little calculus to make it one operation. (N*(N+1))/2 gives you the sum of every number from 1 to N, and there are other formulas for solving more complex sums.
2
13
0
Is there a way to sum up a list of numbers faster than with a for-loop, perhaps in the Python library? Or is that something really only multi-threading / vector processing can do efficiently? Edit: Just to clarify, it could be a list of any numbers, unsorted, just input from the user.
Faster way to sum a list of numbers than with a for-loop?
0.039979
0
0
27,803
851,010
2009-05-12T03:20:00.000
4
0
1
0
python,windows
851,039
6
false
0
0
You can compare len(os.listdir("path")) to zero to see if there are any files in the directory.
1
4
0
Say I want to manipulate some files on a floppy drive or a USB card reader. How do I check to see if the drive in question is ready? (That is, has a disk physically inserted.) The drive letter exists, so os.exists() will always return True in this case. Also, at this point in the process I don't yet know any file names, so checking to see if a given file exists also won't work. Some clarification: the issue here is exception handling. Most of the win32 API calls in question just throw an exception when you try to access a drive that isn't ready. Normally, this would work fine - look for something like the free space, and then catch the raised exception and assume that means there isn't a disk present. However, even when I catch any and all exceptions, I still get an angry exception dialog box from Windows telling me the floppy / card reader isn't ready. So, I guess the real question is - how do I suppress the windows error box?
How do I check if a disk is in a drive using python?
0.132549
0
0
3,839
851,636
2009-05-12T07:52:00.000
3
0
0
0
python,django,django-admin
920,320
17
false
1
0
Note that if instead of pre-selecting a filter value you want to always pre-filter the data before showing it in the admin, you should override the ModelAdmin.queryset() method instead.
2
105
0
How can I change the default filter choice from 'ALL'? I have a field named as status which has three values: activate, pending and rejected. When I use list_filter in Django admin, the filter is by default set to 'All' but I want to set it to pending by default.
Default filter in Django admin
0.035279
0
0
42,742
851,636
2009-05-12T07:52:00.000
2
0
0
0
python,django,django-admin
1,560,919
17
false
1
0
I know that is not the best solution, but i changed the index.html in the admin template, line 25 and 37 like this: 25: <th scope="row"><a href="{{ model.admin_url }}{% ifequal model.name "yourmodelname" %}?yourflag_flag__exact=1{% endifequal %}">{{ model.name }}</a></th> 37: <td><a href="{{ model.admin_url }}{% ifequal model.name "yourmodelname" %}?yourflag__exact=1{% endifequal %}" class="changelink">{% trans 'Change' %}</a></td>
2
105
0
How can I change the default filter choice from 'ALL'? I have a field named as status which has three values: activate, pending and rejected. When I use list_filter in Django admin, the filter is by default set to 'All' but I want to set it to pending by default.
Default filter in Django admin
0.023525
0
0
42,742
854,353
2009-05-12T19:11:00.000
0
0
0
1
python,apache-flex,google-app-engine
854,403
2
false
1
0
Do a HTTP post from Flex to your AppEngine app using the URLRequest class.
1
0
0
I want to communicate using flex client with GAE, I am able to communicate using XMl from GAE to FLex but how should I post from flex3 to python code present on App Engine. Can anyone give me a hint about how to send login information from Flex to python Any ideas suggest me some examples.....please provide me some help Regards, Radhika
How to establish communication between flex and python code build on Google App Engine
0
0
1
1,782
855,191
2009-05-12T22:27:00.000
-18
0
1
0
python,list,size
22,240,449
10
false
0
0
There is no limitation of list number. The main reason which causes your error is the RAM. Please upgrade your memory size.
3
141
0
In Python, how big can a list get? I need a list of about 12000 elements. Will I still be able to run list methods such as sorting, etc?
How Big can a Python List Get?
-1
0
0
205,647
855,191
2009-05-12T22:27:00.000
5
0
1
0
python,list,size
855,195
10
false
0
0
12000 elements is nothing in Python... and actually the number of elements can go as far as the Python interpreter has memory on your system.
3
141
0
In Python, how big can a list get? I need a list of about 12000 elements. Will I still be able to run list methods such as sorting, etc?
How Big can a Python List Get?
0.099668
0
0
205,647
855,191
2009-05-12T22:27:00.000
1
0
1
0
python,list,size
855,200
10
false
0
0
I'd say you're only limited by the total amount of RAM available. Obviously the larger the array the longer operations on it will take.
3
141
0
In Python, how big can a list get? I need a list of about 12000 elements. Will I still be able to run list methods such as sorting, etc?
How Big can a Python List Get?
0.019997
0
0
205,647
855,408
2009-05-12T23:29:00.000
5
0
0
1
python,django,macos
856,033
4
false
1
0
Unless you are planning on going to production with OS X you might not want to bother. If you must do it, go straight to mod_wsgi. Don't bother with mod_python or older solutions. I did mod_python on Apache and while it runs great now, it took countless hours to set up. Also, just to clarify something based on what you said: You're not going to find a mapping between the url path (like /polls) and a script that is being called. Django doesn't work like that. With Django your application is loaded into memory waiting for requests. Once a request comes in it gets dispatched through the url map that you created in urls.py. That boils down to a function call somewhere in your code. That's why for a webserver like Apache you need a module like mod_wsgi, which gives your app a spot in memory in which to live. Compare that with something like CGI where the webserver executes a specific script on demand at a location that is physically mapped between the url and the filesystem. I hope that's helpful and not telling you something you already knew. :)
2
1
0
I've just completed the very very nice django tutorial and it all went swimmingly. One of the first parts of the tutorial is that it says not to use their example server thingie in production, my first act after the tutorial was thus to try to run my app on apache. I'm running OSX 10.5 and have the standard apache (which refuses to run python) and MAMP (which begrudgingly allows it in cgi-bin). The problem is that I've no idea which script to call, in the tutorial it was always localhost:8000/polls but I've no idea how that's meant to map to a specific file. Have I missed something blatantly obvious about what to do with a .htaccess file or does the tutorial not actually explain how to use it somewhere else?
Running django on OSX
0.244919
0
0
1,602
855,408
2009-05-12T23:29:00.000
2
0
0
1
python,django,macos
856,986
4
false
1
0
Yet another option is to consider using a virtual machine for your development. You can install a full version of whatever OS your production server will be running - say, Debian - and run your Apache and DB in the VM. You can connect to the virtual disk in the Finder, so you can still use TextMate (or whatever) on OSX to do your editing. I've had good experiences doing this via VMWare Fusion.
2
1
0
I've just completed the very very nice django tutorial and it all went swimmingly. One of the first parts of the tutorial is that it says not to use their example server thingie in production, my first act after the tutorial was thus to try to run my app on apache. I'm running OSX 10.5 and have the standard apache (which refuses to run python) and MAMP (which begrudgingly allows it in cgi-bin). The problem is that I've no idea which script to call, in the tutorial it was always localhost:8000/polls but I've no idea how that's meant to map to a specific file. Have I missed something blatantly obvious about what to do with a .htaccess file or does the tutorial not actually explain how to use it somewhere else?
Running django on OSX
0.099668
0
0
1,602
856,173
2009-05-13T05:15:00.000
4
0
0
0
python,mysql,linux,perl
856,208
2
false
0
0
Write an insert trigger which duplicates inserted rows to a secondary table. Periodically poll the secondary table for rows with an external application/cronjob; if any rows are in the table, delete them and do your processing (or set a 'processing started' flag and only delete from the secondary table upon successful processing). This will work very nicely for low to medium insert volumes. If you have a ton of data coming at your table, some kind of custom trigger in C is probably your only choice.
2
3
0
I need to launch a server side process off a mysql row insert. I'd appreciate some feedback/suggestions. So far I can think of three options: 1st (least attractive): My preliminary understanding is that I can write a kind of "custom trigger" in C that could fire off a row insert. In addition to having to renew my C skills this would requite a (custom?) recompile of MySQl ... yuck! 2nd (slightly more attractive): I could schedule a cron task server side of a program that I write that would query the table for new rows periodically. This has the benefit of being DB and language independent. The problem with this is that I suffer the delay of the cron's schedule. 3rd (the option I'm leading with): I could write a multi threaded program that would query the table for changes on a single thread, spawning new threads to process the newly inserted rows as needed. This has all the benefits of option 2 with less delay. I'll also mention that I'm leaning towards python for this task, as easy access to the system (linux) commands, as well as some in house perl scripts, is going to be very very useful. I'd appreciate any feedback/suggestion Thanks in advance.
launch a process off a mysql row insert
0.379949
1
0
227
856,173
2009-05-13T05:15:00.000
0
0
0
0
python,mysql,linux,perl
856,210
2
false
0
0
I had this issue about 2 years ago in .NET and I went with the 3rd approach. However, looking back at it, I'm wondering if looking into Triggers with PhpMyAdmin & MySQL isn't the approach to look into.
2
3
0
I need to launch a server side process off a mysql row insert. I'd appreciate some feedback/suggestions. So far I can think of three options: 1st (least attractive): My preliminary understanding is that I can write a kind of "custom trigger" in C that could fire off a row insert. In addition to having to renew my C skills this would requite a (custom?) recompile of MySQl ... yuck! 2nd (slightly more attractive): I could schedule a cron task server side of a program that I write that would query the table for new rows periodically. This has the benefit of being DB and language independent. The problem with this is that I suffer the delay of the cron's schedule. 3rd (the option I'm leading with): I could write a multi threaded program that would query the table for changes on a single thread, spawning new threads to process the newly inserted rows as needed. This has all the benefits of option 2 with less delay. I'll also mention that I'm leaning towards python for this task, as easy access to the system (linux) commands, as well as some in house perl scripts, is going to be very very useful. I'd appreciate any feedback/suggestion Thanks in advance.
launch a process off a mysql row insert
0
1
0
227
858,213
2009-05-13T14:16:00.000
5
0
0
0
python,django,django-models,upload
2,424,900
3
false
1
0
If you added a user field to the model, and have that attribute set before you performed an upload, then you could get the user in to your upload_location function via the instance attribute.
1
3
0
I've got a model like this def upload_location(instance, filename): return 'validate/%s/builds/%s' % (get_current_user(), filename) class MidletPair(models.Model): jad_file = models.FileField(upload_to = upload_location) jar_file = models.FileField(upload_to = upload_location) upload_to=tempfile.gettempdir() How can I get the current user in upload_location()... ? Side note: Looking up django stuff is confusing as theres a lot of pre-1.0 stuff around on the net.
How to save django FileField to user folder?
0.321513
0
0
5,337
859,319
2009-05-13T17:34:00.000
2
0
0
0
python,django
859,951
3
false
1
0
Templates are just strings not file names. Probably your best option is to monkey patch render_to_response and/or direct_to_template and copy the filename arg into the context.
1
8
0
For debugging purposes, I would like to have a variable in all my templates holding the path of the template being rendered. For example, if a view renders templates/account/logout.html I would like {{ template_name }} to contain the string templates/account/logout.html. I don't want to go and change any views (specially because I'm reusing a lot of apps), so the way to go seems to be a context processor that introspects something. The question is what to introspect. Or maybe this is built in and I don't know about it?
Getting the template name in django template
0.132549
0
0
4,840
859,594
2009-05-13T18:28:00.000
0
1
1
0
python,windows,path
859,615
9
false
0
0
What's it set to? Have you tried creating a PYTHONPATH environment variable?
4
12
0
I'm trying to change my PYTHONPATH. I've tried to change it in "My Computer" etc, but it doesn't exist there. I searched in the registry in some places, and even ran a whole search for the word 'PYTHONPATH', but to no avail. However, it Python I can easily see it exists. So where is it?
Can't find my PYTHONPATH
0
0
0
45,286
859,594
2009-05-13T18:28:00.000
0
1
1
0
python,windows,path
859,618
9
false
0
0
You need modify your environment variables. How to do this depends on which version of Windows you have. If the PYTHONPATH variable doesn't exist, you have to create it. It might not exist if you haven't already created it.
4
12
0
I'm trying to change my PYTHONPATH. I've tried to change it in "My Computer" etc, but it doesn't exist there. I searched in the registry in some places, and even ran a whole search for the word 'PYTHONPATH', but to no avail. However, it Python I can easily see it exists. So where is it?
Can't find my PYTHONPATH
0
0
0
45,286
859,594
2009-05-13T18:28:00.000
1
1
1
0
python,windows,path
3,079,003
9
false
0
0
MacOS 10.5.8, Python 2.6, Eclipse+Pydev 1.5.7 Python installation's site-package is, for example: /Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages create symlinks YOUR LIBRARY inside into site-package, for example: cd /Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages ln -s /path/to/YOUR/LIBRARY/ YOUR_LIBRARY_NAME Now You can use in commandline: import YOUR_LIBRARY_NAME run Eclipse with Pydev, go to Preferences->Pydev->Interpreter Python remove Your Python interpreter record, if exists; click New and add Python 2.6 interpreter path, for example: /Library/Frameworks/Python.framework/Versions/2.6/bin/python2.6 notice, that Eclipse Pydev display Python System Library, accept that in Library section click New Folder and write path to YOUR LIBRARY, for example: /path/to/YOUR/LIBRARY/ click Apply - it is essential, because Eclipse Pydev built now his own "library map", when this operation finish - click [OK] close Eclipse run Eclipse again - now You should use in Pydev: import YOUR_LIBRARY_NAME
4
12
0
I'm trying to change my PYTHONPATH. I've tried to change it in "My Computer" etc, but it doesn't exist there. I searched in the registry in some places, and even ran a whole search for the word 'PYTHONPATH', but to no avail. However, it Python I can easily see it exists. So where is it?
Can't find my PYTHONPATH
0.022219
0
0
45,286
859,594
2009-05-13T18:28:00.000
0
1
1
0
python,windows,path
67,562,437
9
false
0
0
I had same problem and oliver-zehentleitner's answer in github solved my problem. He said: Maybe You install package with pip for python2 and run with python3, just try to install with pip3 or python3 -m pip install python-binance and then run your script again. I hope this can solve yours too.
4
12
0
I'm trying to change my PYTHONPATH. I've tried to change it in "My Computer" etc, but it doesn't exist there. I searched in the registry in some places, and even ran a whole search for the word 'PYTHONPATH', but to no avail. However, it Python I can easily see it exists. So where is it?
Can't find my PYTHONPATH
0
0
0
45,286
861,864
2009-05-14T06:37:00.000
1
0
1
0
python,security,scripting,scripting-language,embedded-language
861,969
13
false
0
0
I'd be wary about releasing such applications into the wild for fear of someone either accidentally, or maliciously, adding destructive code to the file. Your native code that's "in the wild" is equally vulnerable to this attack; that it is in machine code is just a speed bump, and no security. If you are extremely paranoid and want a higher speedbump, you could make your native app that hosts the script instance check a hash of the content. Then accidential changes are impossible; only deliberate changes would go to the trouble of updating the checksum. You could go further and check they were signed with a public key too; then only hacking your native app could let new scripts in. But the sandboxing? Don't worry about it!
3
13
0
In the many Python applications I've created, I often create simple modules containing nothing but constants to be used as config files. Additionally, because the config file is actually a Python code file, I can add simple logic for changing variables depending on a debug level, etc. While this works great for internal applications, I'd be wary about releasing such applications into the wild for fear of someone either accidentally, or maliciously, adding destructive code to the file. The same would hold true for using Python as an embedded scripting language. Is there a subset of Python that is deemed "safe" for embedding? I realize how safe it can be considered is fairly subjective. However, Java Applets and Flash both have their security sandbox well defined. I'm wondering if there's a version of Python that has similar rules? EDIT: I'm asking not so much because of the config file approach, but because I'm interested in implementing some scripting/plugin mechanisms into a newer app and don't want a plugin or script to be able to, say, delete files. That goes beyond the scope of what the application should be able to do.
Is there a "safe" subset of Python for use as an embedded scripting language?
0.015383
0
0
4,570
861,864
2009-05-14T06:37:00.000
1
0
1
0
python,security,scripting,scripting-language,embedded-language
1,000,418
13
false
0
0
It's a little hard to understand what you're trying to do -- not enough details. Are you hosting the native app and allowing the users to write plugins? Consider using an OS-level solution by running the Python application as a separate runtime process inside a jail/chroot/similar, and communicating over sockets. Are you expecting your customers to host the native app and let "untrusted parties" write plugins? Is there a reason the solution above won't work? (E.g., the customer would like to deploy on weird OSs without such options...) Are you expecting the same people to host the native app and the "untrusted script" and want to protect them from themselves? In the sense of protecting them from writing "os.remove" and having it do what they wrote? Can you explain why? Note that sandboxing alone is often not enough without stricter constraints (maximum CPU cycles, maximum memory, memory ownership issues...)? What kind of maliciousness do you want to stop? Note that here, too, OSs have wonderful capabilities (priorities, killing processes, ulimits) that not all sandboxing environments replicate -- and are certainly less security-tested than the things in OSs. (I'd trust Linux not to have breakable ulimits before I'd trust PyPy not to enable a malicious coder to take up unbounded amounts of memory, simply because Linux has been attacked in the wild more.)
3
13
0
In the many Python applications I've created, I often create simple modules containing nothing but constants to be used as config files. Additionally, because the config file is actually a Python code file, I can add simple logic for changing variables depending on a debug level, etc. While this works great for internal applications, I'd be wary about releasing such applications into the wild for fear of someone either accidentally, or maliciously, adding destructive code to the file. The same would hold true for using Python as an embedded scripting language. Is there a subset of Python that is deemed "safe" for embedding? I realize how safe it can be considered is fairly subjective. However, Java Applets and Flash both have their security sandbox well defined. I'm wondering if there's a version of Python that has similar rules? EDIT: I'm asking not so much because of the config file approach, but because I'm interested in implementing some scripting/plugin mechanisms into a newer app and don't want a plugin or script to be able to, say, delete files. That goes beyond the scope of what the application should be able to do.
Is there a "safe" subset of Python for use as an embedded scripting language?
0.015383
0
0
4,570
861,864
2009-05-14T06:37:00.000
4
0
1
0
python,security,scripting,scripting-language,embedded-language
861,875
13
false
0
0
No there is no production ready subset of Python that is "safe". Python has had a few sand box modules which were deprecated due to deficiencies. Your best bet is to either create your own parser, or isolate the python process with syscall hooks and a jailed account. Some people might point you to PyPy, but it is unfinished.
3
13
0
In the many Python applications I've created, I often create simple modules containing nothing but constants to be used as config files. Additionally, because the config file is actually a Python code file, I can add simple logic for changing variables depending on a debug level, etc. While this works great for internal applications, I'd be wary about releasing such applications into the wild for fear of someone either accidentally, or maliciously, adding destructive code to the file. The same would hold true for using Python as an embedded scripting language. Is there a subset of Python that is deemed "safe" for embedding? I realize how safe it can be considered is fairly subjective. However, Java Applets and Flash both have their security sandbox well defined. I'm wondering if there's a version of Python that has similar rules? EDIT: I'm asking not so much because of the config file approach, but because I'm interested in implementing some scripting/plugin mechanisms into a newer app and don't want a plugin or script to be able to, say, delete files. That goes beyond the scope of what the application should be able to do.
Is there a "safe" subset of Python for use as an embedded scripting language?
0.061461
0
0
4,570
863,253
2009-05-14T13:11:00.000
2
1
1
0
python,collective-intelligence
986,107
6
false
0
0
I suggest translating them to C#. I have been porting chapter 2 "Recommendations" to VB.Net. Along the way I'm learning Python as a side-effect. Toby does some amazing things with Python lists. Dealing with the the extra Python libraries is another story. Ndelicious is a close match to pyDelicious, but it is missing a few key features (popular posts!).
3
3
0
I'm currently reading a great book called 'Programming Collective Intelligence' by Toby Segaran (which i highly recommend) The code examples are all written in Python, and as I have already learnt one new language this year (graduating from VB.net to C#) i'm not keen to jump on another learning curve. This leaves my with the issue of translating the python examples into C#. Question is: How critical is it that the code stay in python? Are there thing in python that I can't do in a normal managed statically typed language?
Python and Collective Intelligence
0.066568
0
0
2,273
863,253
2009-05-14T13:11:00.000
1
1
1
0
python,collective-intelligence
863,568
6
false
0
0
The book is about algorithms, not the details of programming, and the language of choice is just to make the examples concrete. As the author says, "The code examples in this book are written in Python... but I provide explanations of all the algorithms so that programmers of other languages can follow." (p. xv) Python is a great language and easy to learn, but I suspect the difficulties in applying ideas from the book will not be in the translating of the code to another language or set of libraries, but in understanding the ideas and modifying the code to suite your needs. I think there are two main reasons to stay with a language you're familiar with: 1) when your code doesn't work, if you're writing in an unfamiliar language, you won't know where to start looking for errors, e.g. if you're like most people you'll even start wondering if it's due to a bug in Python, which it won't be, but you'll wonder and it will distract. 2) There are just natural limits to how much you can remember in a certain length of time; and learning a language at the same time will give you twice as much to remember. It depends though how well you know C#, and what you lose by leaving it.
3
3
0
I'm currently reading a great book called 'Programming Collective Intelligence' by Toby Segaran (which i highly recommend) The code examples are all written in Python, and as I have already learnt one new language this year (graduating from VB.net to C#) i'm not keen to jump on another learning curve. This leaves my with the issue of translating the python examples into C#. Question is: How critical is it that the code stay in python? Are there thing in python that I can't do in a normal managed statically typed language?
Python and Collective Intelligence
0.033321
0
0
2,273
863,253
2009-05-14T13:11:00.000
20
1
1
0
python,collective-intelligence
863,292
6
true
0
0
One challenge you'll find is that not only are the algorithms implemented in Python, but the book makes extensive use of Python libraries like BeautifulSoup, Numpy, PIL, and others (see appendix A). I doubt there are any specifics of the algorithms that you couldn't port to another language, but you'll have trouble working through the exercises. Also, to translate the code, you'll have to learn Python at least a little bit, no? I suggest you just dive in and learn Python. You can use IronPython if you have any concern about interoperability with your C# projects.
3
3
0
I'm currently reading a great book called 'Programming Collective Intelligence' by Toby Segaran (which i highly recommend) The code examples are all written in Python, and as I have already learnt one new language this year (graduating from VB.net to C#) i'm not keen to jump on another learning curve. This leaves my with the issue of translating the python examples into C#. Question is: How critical is it that the code stay in python? Are there thing in python that I can't do in a normal managed statically typed language?
Python and Collective Intelligence
1.2
0
0
2,273
864,883
2009-05-14T18:16:00.000
1
0
1
0
python,file-io
4,588,481
5
false
0
0
for row in matrix: file.write(" ".join(map(str,row))+"\n") This works for me... and writes the output in matrix format
1
10
0
I need to write a series of matrices out to a plain text file from python. All my matricies are in float format so the simple file.write() and file.writelines() do not work. Is there a conversion method I can employ that doesn't have me looping through all the lists (matrix = list of lists in my case) converting the individual values? I guess I should clarify, that it needn't look like a matrix, just the associated values in an easy to parse list, as I will be reading in later. All on one line may actually make this easier!
How do I write a float list of lists to file in Python
0.039979
0
0
70,119
864,887
2009-05-14T18:17:00.000
1
0
0
0
python,windows-mobile,mobile-phones
864,988
1
false
1
1
Can't help you much with Python\CE but if you want a great db for mobile devices SQLLite will do the job for you. If you do a quick google you'll find there are libraries for connecting to SQLLite with Python too.
1
0
0
I've wanted to get into Python development for awhile and most of my programming experience has been in .NET and no mobile development. I recently thought of a useful app to make for my windows mobile phone and thought this could be a great first Python project. I did a little research online and found PyCe which I think is what I would need to get started on the app? Can anyone with some experience in this area point me in the right direction? What to download to get started, what lightweight database I could use, etc? Thanks in advance!
Beginning Windows Mobile 6.1 Development With Python
0.197375
0
0
1,216
865,082
2009-05-14T18:56:00.000
1
0
1
1
python,shell,wxpython,multiprocessing
892,646
2
true
0
0
First create the shell Decouple the shell from your app by making its locals empty Create your code string Compile the code string and get a code object Execute the code object in the shell from wx.py.shell import Shell frm = wx.Frame(None) sh = Shell(frm) frm.Show() sh.interp.locals = {} codeStr = """ from multiprocessing import Process, Queue def f(q): q.put([42, None, 'hello']) q = Queue() p = Process(target=f, args=(q,)) p.start() print q.get() # prints "[42, None, 'hello']" p.join() """ code = compile(codeStr, '', 'exec') sh.interp.runcode(code) Note: The codeStr I stole from the first poster may not work here due to some pickling issues. But the point is you can execute your own codeStr remotely in a shell.
1
1
0
I would like to create a shell which will control a separate process that I created with the multiprocessing module. Possible? How? EDIT: I have already achieved a way to send commands to the secondary process: I created a code.InteractiveConsole in that process, and attached it to an input queue and an output queue, so I can command the console from my main process. But I want it in a shell, probably a wx.py.shell.Shell, so a user of the program could use it.
Python: Plugging wx.py.shell.Shell into a separate process
1.2
0
0
1,527
865,382
2009-05-14T19:58:00.000
2
1
1
0
python,grep,plone,zope
5,189,472
12
false
0
0
And simply because there are not enough answers... If you're developing routinely, it's well worth the effort to install Eclipse with Pydev (or even easier, Aptana Studio - which is a modified Eclipse), in which case the find tools are right there.
3
23
0
I'm working on a Python program that makes heavy use of eggs (Plone). That means there are 198 directories full of Python code I might want to search through while debugging. Is there a good way to search only the .py files in only those directories, avoiding unrelated code and large binary files?
How do you grep through code that lives in many different directories?
0.033321
0
0
12,967
865,382
2009-05-14T19:58:00.000
4
1
1
0
python,grep,plone,zope
5,131,554
12
false
0
0
This problem was the motivation for the creation of collective.recipe.omelette. It is a buildout recipe which can symlink all the eggs from your working set into one directory structure, which you can point your favorite search utility at.
3
23
0
I'm working on a Python program that makes heavy use of eggs (Plone). That means there are 198 directories full of Python code I might want to search through while debugging. Is there a good way to search only the .py files in only those directories, avoiding unrelated code and large binary files?
How do you grep through code that lives in many different directories?
0.066568
0
0
12,967
865,382
2009-05-14T19:58:00.000
2
1
1
0
python,grep,plone,zope
5,131,426
12
false
0
0
Just in case you want a non-commandline OSS solution... I use pycharm. It has built in support for buildout. You point it at a buildout generated bin/instance and it sets the projects external dependencies to all the eggs used by the instance. Then all the IDE's introspection and code navigation work nicely. Goto definition, goto instances, refactoring support and of course search.
3
23
0
I'm working on a Python program that makes heavy use of eggs (Plone). That means there are 198 directories full of Python code I might want to search through while debugging. Is there a good way to search only the .py files in only those directories, avoiding unrelated code and large binary files?
How do you grep through code that lives in many different directories?
0.033321
0
0
12,967
865,973
2009-05-14T21:42:00.000
21
0
1
0
python,algorithm
865,997
8
false
0
0
To delete half the N images you cannot be faster than O(N)! You do know that the O() notation means (among other things) that constant multiplicative factors are irrelevant, yes?
4
1
0
I have a folder with thousands of images. I want to delete every other image. What is the most effective way to do this? Going through each one with i%2==0 is still O(n). Is there a fast way to do this (preferably in Python)? Thx
Algorithm: How to Delete every other file
1
0
0
3,527
865,973
2009-05-14T21:42:00.000
3
0
1
0
python,algorithm
866,018
8
false
0
0
Going through each one with i%2==0 is still O(n). Is there a fast way to do this (preferably in Python)? The only way to be faster than O(n) is if your files are already sorted, and you only want to delete 1 file. You said i%2==0, this means you are deleting every "even" file. O(n/2) is still O(n)
4
1
0
I have a folder with thousands of images. I want to delete every other image. What is the most effective way to do this? Going through each one with i%2==0 is still O(n). Is there a fast way to do this (preferably in Python)? Thx
Algorithm: How to Delete every other file
0.07486
0
0
3,527
865,973
2009-05-14T21:42:00.000
1
0
1
0
python,algorithm
866,009
8
false
0
0
If you wanted to delete Log(n) files, there would be... You can store images in a database, though ( MySQL has a "blob" type, among several others, that will store your images). Then you could do it in O(1) if you named them smartly. /edit i hate how i have to use shorthand and bad grammar to get my answers in quickly!!! if you're looking for a python equivalent of rm -rf *2.img *4.img *6.img *8.img *0.img, know that the computer still has to go through the entire list of files
4
1
0
I have a folder with thousands of images. I want to delete every other image. What is the most effective way to do this? Going through each one with i%2==0 is still O(n). Is there a fast way to do this (preferably in Python)? Thx
Algorithm: How to Delete every other file
0.024995
0
0
3,527
865,973
2009-05-14T21:42:00.000
2
0
1
0
python,algorithm
866,005
8
false
0
0
I fail to see any conceivable way in which deleting n/2 files could be faster than O(n), unless the filesystem has some special feature for deleting large numbers of files (but I don't think that actually exists in practice, if it's even possible)
4
1
0
I have a folder with thousands of images. I want to delete every other image. What is the most effective way to do this? Going through each one with i%2==0 is still O(n). Is there a fast way to do this (preferably in Python)? Thx
Algorithm: How to Delete every other file
0.049958
0
0
3,527
866,737
2009-05-15T02:16:00.000
0
0
0
1
python,shell
866,750
3
false
0
0
You say "pipe" so I assume you're dealing with text output from the subprocesses. A simple solution may be to just write output to files? e.g. in the subprocess: Redirect output %TEMP%\output.txt On exit, copy output.txt to a directory your main process is watching. In the main process: Every second, examine directory for new files. When files found, process and remove them. You could encode the subprocess name in the output filename so you know how to process it.
1
1
0
I want to pipe [edit: real-time text] the output of several subprocesses (sometimes chained, sometimes parallel) to a single terminal/tty window that is not the active python shell (be it an IDE, command-line, or a running script using tkinter). IPython is not an option. I need something that comes with the standard install. Prefer OS-agnostic solution, but needs to work on XP/Vista. I'll post what I've tried already if you want it, but it’s embarrassing.
Creating a new terminal/shell window to simply display text
0
0
0
1,202
867,175
2009-05-15T06:03:00.000
1
0
0
0
python,tcp,database-connection
867,433
3
false
0
0
If you want to implement timeouts that work no matter how the client library is connecting to the server, it's best to attempt the DB operations in a separate thread, or, better, a separate process, which a "monitor" thread/process can kill if needed; see the multiprocessing module in Python 2.6 standard library (there's a backported version for 2.5 if you need that). A process is better because when it's killed the operating system will take care of deallocating and cleaning up resources, while killing a thread is always a pretty unsafe and messy business.
2
0
0
I am writing a code in python in which I established a connection with database. I have queries in a loop. While queries being executed in the loop , If i unplug the network cable it should stop with an exception. But this not happens, When i again plug yhe network cabe after 2 minutes it starts again from where it ended. I am using linux and psycopg2. It is not showing exception
db connection in python
0.066568
1
0
442
867,175
2009-05-15T06:03:00.000
2
0
0
0
python,tcp,database-connection
867,202
3
false
0
0
Your database connection will almost certainly be based on a TCP socket. TCP sockets will hang around for a long time retrying before failing and (in python) raising an exception. Not to mention and retries/automatic reconnection attempts in the database layer.
2
0
0
I am writing a code in python in which I established a connection with database. I have queries in a loop. While queries being executed in the loop , If i unplug the network cable it should stop with an exception. But this not happens, When i again plug yhe network cabe after 2 minutes it starts again from where it ended. I am using linux and psycopg2. It is not showing exception
db connection in python
0.132549
1
0
442
869,885
2009-05-15T17:17:00.000
1
0
1
0
python,loops
24,374,584
17
false
0
0
for var in range(10,-1,-1) works
1
357
0
I am trying to loop from 100 to 0. How do I do this in Python? for i in range (100,0) doesn't work.
Loop backwards using indices in Python?
0.011764
0
0
449,182
870,520
2009-05-15T19:48:00.000
0
0
1
0
python,filter,whitelist
870,565
10
false
0
0
I'd use a regex. For lowercase match [a-z].
1
22
0
Imagine a string, like 'Agh#$%#%2341- -!zdrkfd' and I only wish to perform some operating on it such that only the lowercase letters are returned (as an example), which in this case would bring 'ghzdrkfd'. How do you do this in Python? The obvious way would be to create a list, of characters, 'a' through 'z', then iterate over the characters in my string and build a new string, character by character, of those in my list only. This seems primitive. I was wondering if regular expressions are appropriate. Replacing unwanted characters seems problematic and I tend to prefer whitelisting over blacklisting. The .match function does not seem appropriate. I have looked over the appropriate page on the Python site, but have not found a method which seems to fit. If regular expressions are not appropriate and the correct approach is looping, is there a simple function which "explodes" a string into a list? Or am I just hitting another for loop there?
How do you filter a string such that only characters in your list are returned?
0
0
0
31,214
871,447
2009-05-16T01:36:00.000
6
0
0
1
python,pipe,fork
871,515
4
false
0
0
Using fcntl.fcntl(readPipe, fcntl.F_SETFL, os.O_NONBLOCK) Before invoking the read() solved both problems. The read() call is no longer blocking and the data is appearing after just a flush() on the writing end.
1
13
0
I've recently needed to write a script that performs an os.fork() to split into two processes. The child process becomes a server process and passes data back to the parent process using a pipe created with os.pipe(). The child closes the 'r' end of the pipe and the parent closes the 'w' end of the pipe, as usual. I convert the returns from pipe() into file objects with os.fdopen. The problem I'm having is this: The process successfully forks, and the child becomes a server. Everything works great and the child dutifully writes data to the open 'w' end of the pipe. Unfortunately the parent end of the pipe does two strange things: A) It blocks on the read() operation on the 'r' end of the pipe. Secondly, it fails to read any data that was put on the pipe unless the 'w' end is entirely closed. I immediately thought that buffering was the problem and added pipe.flush() calls, but these didn't help. Can anyone shed some light on why the data doesn't appear until the writing end is fully closed? And is there a strategy to make the read() call non blocking? This is my first Python program that forked or used pipes, so forgive me if I've made a simple mistake.
Python program using os.pipe and os.fork() issue
1
0
0
16,065
872,065
2009-05-16T09:34:00.000
1
0
0
0
python,django,django-templates
875,985
6
false
1
0
Kind of an oblique answer, but if being able to use tools like Dreamweaver on your templates is important to you, you may find you like Genshi better than Django Templates, and it's easy enough to switch your template engine. Genshi is an XML templating language that is one of the inheritors of the Zope TAL family. Your template file is a valid XML file, so you can open it in any XML aware tool. Personally, once I got used to using XML templates, I couldn't go back, but they are slower to process ( an xml parser has to run behind the scenes ) and they require valid XHTML in your output which can be a good or a bad thing. ( Invalid user submitted html content for example would need to be forced clean using something like Beautiful Soup or ElementTree ).
2
20
0
Is there a tool out there for visually building Django templates? Thanks
Visual Editor for Django Templates?
0.033321
0
0
10,614
872,065
2009-05-16T09:34:00.000
2
0
0
0
python,django,django-templates
874,222
6
false
1
0
There's no WYSIWYG tool like Dreamweaver. But highligting is possible. I am using Kate to edit my templates. For instance when you comment in Django template it inserts {% comment %}.
2
20
0
Is there a tool out there for visually building Django templates? Thanks
Visual Editor for Django Templates?
0.066568
0
0
10,614
872,290
2009-05-16T12:01:00.000
2
0
1
0
python,string
872,295
9
false
0
0
You're basically testing whether a member is in a set or not, right? If so, and because you said you have lots of memory, why not just load all the words as keys in memcache, and then for every word, just check if it is present in memcache or not. Or use that data structure that is used by bash to autocomplete command names - this is fast and highly efficient in memory (can't remember the name).
2
11
0
I have a file containing roughly all the words in English (~60k words, ~500k characters). I want to test whether a certain word I receive as input is "in English" (i.e. if this exact word is in the list). What would be the most efficient way to do this in Python? The trivial solution is to load the file into a list and check whether the word is in that list. The list can be sorted, which I believe will shrink the complexity to O(logn). However I'm not sure about how Python implements searching through lists, and whether there's a performance penalty if such a large list is in memory. Can I "abuse" the fact I can put a cap on the length of words? (e.g. say the longest one is 15 characters long). Please note I run the application on a machine with lots of memory, so I care less for memory consumption than for speed and CPU utilization. Thanks
Most Efficient Way to Find Whether a Large List Contains a Specific String (Python)
0.044415
0
0
15,715
872,290
2009-05-16T12:01:00.000
2
0
1
0
python,string
872,353
9
false
0
0
Two things: The Python 'mutable set' type has an 'add' method ( s.add(item) ), so you could go right from reading (a line) from your big file straight into a set without using a list as an intermediate data structure. Python lets you 'pickle' a data structure, so you could save your big set to a file and save the time of reinitiating the set. Second, I've been looking for a list of all the single-syllable words in English for my own amusement, but the ones I've found mentioned seem to be proprietary. If it isn't being intrusive, could I ask whether your list of English words can be obtained by others?
2
11
0
I have a file containing roughly all the words in English (~60k words, ~500k characters). I want to test whether a certain word I receive as input is "in English" (i.e. if this exact word is in the list). What would be the most efficient way to do this in Python? The trivial solution is to load the file into a list and check whether the word is in that list. The list can be sorted, which I believe will shrink the complexity to O(logn). However I'm not sure about how Python implements searching through lists, and whether there's a performance penalty if such a large list is in memory. Can I "abuse" the fact I can put a cap on the length of words? (e.g. say the longest one is 15 characters long). Please note I run the application on a machine with lots of memory, so I care less for memory consumption than for speed and CPU utilization. Thanks
Most Efficient Way to Find Whether a Large List Contains a Specific String (Python)
0.044415
0
0
15,715
872,695
2009-05-16T16:01:00.000
4
1
0
0
php,python,mod-python
872,913
6
false
0
0
I think you have some misconceptions about how HTTP works. Nothing in the http standard requires you to have a certain file as a resource. It is just the way how mod_php works, that for a given path, this path is translated to a php file on the disk of the server, which in turn is interpreted by the compiler. The mod_python module on the other hand is much more generic, it allows you to map any resource to a call to some python object. It just happens that some configurations are available out of the box, to make it easier to start with. In most cases the dispatch of the url is managed by your framework, and how that works is up to the framework implementor. Because of the generic nature of the mod_python module you are also able to access some apache features which are not available in the mod_php module, for instance you may write your own authentication handler, which my not only apply to your python webapp, but also to other apps in your apache as well.
5
4
0
Why mod_python is oop but mod_php is not ? Example :We go to www.example.com/dir1/dir2 if you use mod_python apache opens www/dir1.py and calls dir2 method but if you use php module apache opens www/dir1/dir2/index.php
mod_php vs mod_python
0.132549
0
0
2,975
872,695
2009-05-16T16:01:00.000
-1
1
0
0
php,python,mod-python
872,710
6
false
0
0
Perhaps I misunderstand your question, but both Python and PHP support both procedural and object-oriented programming. (Though one could argue that Python's support for OO is the stronger of the two.)
5
4
0
Why mod_python is oop but mod_php is not ? Example :We go to www.example.com/dir1/dir2 if you use mod_python apache opens www/dir1.py and calls dir2 method but if you use php module apache opens www/dir1/dir2/index.php
mod_php vs mod_python
-0.033321
0
0
2,975
872,695
2009-05-16T16:01:00.000
0
1
0
0
php,python,mod-python
873,885
6
false
0
0
in PHP you can program your web pages the top-to-bottom scripts, procedural programming and function calls, OOP. this is the main reason why PHP was first created, and how it evolved. mod_php is just a module for web servers to utilize PHP as a preprocessor. so it just passes HTTP information and the PHP script to PHP interpreter. the PHP way of web page creation is do what you want; write a top-to-bottom script, define functions in different files and include those and call functions, or write your app in OOP, you can also use many full-featured frameworks today to make sure your application design and structure meets today best practices and design patterns. I'm new to Python, and am not familiar with web programming with python. but as much as I know, python was not created to make web programming easier. it was intended to be a general purpose programming language, so although it might be possible to write simple top-to-bottom scripts in python and run them as web page responses (I'm not sure if such thing is possible), it is not the pythonic way, and so I think developers of the mod_python wanted web programming in python to be in a pythonic way.
5
4
0
Why mod_python is oop but mod_php is not ? Example :We go to www.example.com/dir1/dir2 if you use mod_python apache opens www/dir1.py and calls dir2 method but if you use php module apache opens www/dir1/dir2/index.php
mod_php vs mod_python
0
0
0
2,975
872,695
2009-05-16T16:01:00.000
8
1
0
0
php,python,mod-python
873,822
6
true
0
0
Let's talk about mod_python vs. mod_php. Since the Python language is NOT specifically designed for serving web pages, mod_python must do some additional work. Since the PHP language IS specifically designed to serve web pages, mod_php simply starts a named PHP module. In the case of mod_python (different from mod_fastcgi or mod_wsgi), the designer of mod_python decided that the best way to invoke Python is to call a method of an object defined in a module. Hopefully, that method of that object will write the headers and web page content to stdout. In the case of mod_wsgi, the designer decided that the best way to invoke Python is to call a function (or callable object) in a module. Hopefully that function will use the supplied object to create header and return a list strings with the web page content. In the case of mod_php, they just invoke the module because PHP modules are designed to serve web pages. The program runs and the result of that run is a page of content; usually HTML. The reason mod_php works one way, mod_python works another and mod_wsgi works a third way is because they're different. Written by different people with different definitions of the way to produce a web page. The php page can be object-oriented. A mod_wsgi function may be a callable object or it may be a simplef unction. Those are design choices. The mod_python requirement for a class is a design choice made by the designer of mod_python. The reason "why" is never useful. The reason "why" is because someone decided to design it that way.
5
4
0
Why mod_python is oop but mod_php is not ? Example :We go to www.example.com/dir1/dir2 if you use mod_python apache opens www/dir1.py and calls dir2 method but if you use php module apache opens www/dir1/dir2/index.php
mod_php vs mod_python
1.2
0
0
2,975
872,695
2009-05-16T16:01:00.000
4
1
0
0
php,python,mod-python
872,824
6
false
0
0
Because mod_python is abstracting the URL into a "RPC-like" mechanism. You can achieve the same in PHP. I always did it by hand, but I am pretty sure there are prepackaged pear modules for this. Note the mod_python behavior is not forcibly "the best". It all amounts to the type of design you want to give to your application, and how it behaves to the clients. As far as I see, the mod_python approach assumes that for every URL you have a function, like mapping the module structure into a URL tree. This is technically not a particularly nice approach, because there's a tight correlation between the technology you are using (mod_python) and the URL layout of your application. On the reason why, theres' no reason. Some people like one food, and some other like another. Design is, in some cases, a matter of taste and artistic choices, not only technical restrains.
5
4
0
Why mod_python is oop but mod_php is not ? Example :We go to www.example.com/dir1/dir2 if you use mod_python apache opens www/dir1.py and calls dir2 method but if you use php module apache opens www/dir1/dir2/index.php
mod_php vs mod_python
0.132549
0
0
2,975
872,737
2009-05-16T16:19:00.000
1
0
0
0
python,ruby,user-interface
873,925
3
false
0
1
I would recommend PyGame.
2
1
0
using Ruby or Python, does someone know how to draw on the screen, covering up any other window? Kind of like, press a key, and the program will show current weather or stock quote on the screen (using the whole screen as the canvas), and then press the key again, and everything restores to the same as before? (like Mac OS X's dash board).
does someone know how to show content on screen (covering up any window) using Ruby or Python?
0.066568
0
0
179
872,737
2009-05-16T16:19:00.000
4
0
0
0
python,ruby,user-interface
872,757
3
true
0
1
You could use the systems dashboard (desktop widgets, or whatever it's called) API. In order to do that you need bindings to it for Python or Ruby. Alternatively you could use some generic gui toolkit or application framework and just create a frameless window with transparent background. Then you need to be sure that the chosen toolkit supports 'always-on-top' options on your desired platform(s).
2
1
0
using Ruby or Python, does someone know how to draw on the screen, covering up any other window? Kind of like, press a key, and the program will show current weather or stock quote on the screen (using the whole screen as the canvas), and then press the key again, and everything restores to the same as before? (like Mac OS X's dash board).
does someone know how to show content on screen (covering up any window) using Ruby or Python?
1.2
0
0
179
873,089
2009-05-16T19:17:00.000
1
0
1
1
python,debugging,arguments,pdb
67,887,744
4
false
0
0
python3 -m pdb myscript.py -a val if using argparse with flag "a" and value "val"
1
22
0
I've got python script (ala #! /usr/bin/python) and I want to debug it with pdb. How can I pass arguments to the script? I have a python script and would like to debug it with pdb. Is there a way that I can pass arguments to the scripts?
How do you pass script arguments to pdb (Python)?
0.049958
0
0
12,717
873,564
2009-05-16T23:45:00.000
0
0
1
0
python
873,572
3
false
0
0
I would probably create a timesheet object for each week, or pay period. Each timesheet object might have a collection of days, with hours worked or times clocked in and out. For persistent storage for a web site, I'd use a database like mysql. For an application running on a single machine I'd maybe use pickle, or a flat file system maybe.
1
1
0
Say I make a program that keeps track of the days I worked and the hours I worked, would I use a dictionary? And how would I differentiate from a Monday on week 1 from a Monday on week 2? How do I get it to store this information after I close the program? (Python Language)
Timesheet Program to Track Days/Hours worked?
0
0
0
3,319
874,461
2009-05-17T12:02:00.000
12
0
0
0
python,matlab,file-io,scipy,mat-file
66,453,257
12
false
0
0
There is a great library for this task called: pymatreader. Just do as follows: Install the package: pip install pymatreader Import the relevant function of this package: from pymatreader import read_mat Use the function to read the matlab struct: data = read_mat('matlab_struct.mat') use data.keys() to locate where the data is actually stored. The keys will usually look like: dict_keys(['__header__', '__version__', '__globals__', 'data_opp']). Where data_opp will be the actual key which stores the data. The name of this key can ofcourse be changed between different files. Last step - Create your dataframe: my_df = pd.DataFrame(data['data_opp']) That's it :)
1
508
1
Is it possible to read binary MATLAB .mat files in Python? I've seen that SciPy has alleged support for reading .mat files, but I'm unsuccessful with it. I installed SciPy version 0.7.0, and I can't find the loadmat() method.
Read .mat files in Python
1
0
0
566,507
874,476
2009-05-17T12:09:00.000
7
1
0
1
python,unix,root,sudo
874,519
3
false
0
0
The concept of "admin-privileges" in our day of fine grained privilege control is becoming hard to define. If you are running on unix with "traditional" access control model, getting the effective user id (available in os module) and checking that against root (0) could be what you are looking for. If you know accessing a file on the system requires the privileges you want your script to have, you can use the os.access() to check if you are privileged enough. Unfortunately there is no easy nor portable method to give. You need to find out or define the security model used, what system provided APIs are available to query and set privileges and try to locate (or possibly implement yourself) the appropriate python modules that can be used to access the API. The classic question, why do you need to find out? What if your script tries to do what it needs to do and "just" catches and properly handles failures?
1
2
0
how can i check admin-privileges for my script during running?
Admin privileges for script
1
0
0
2,996
874,815
2009-05-17T15:20:00.000
1
0
0
1
python,subprocess,stdout,popen
2,328,115
10
false
0
0
I've been running into this problem as well. The problem occurs because you are trying to read stderr as well. If there are no errors, then trying to read from stderr would block. On Windows, there is no easy way to poll() file descriptors (only Winsock sockets). So a solution is not to try and read from stderr.
2
47
0
I'd like to use the subprocess module in the following way: create a new process that potentially takes a long time to execute. capture stdout (or stderr, or potentially both, either together or separately) Process data from the subprocess as it comes in, perhaps firing events on every line received (in wxPython say) or simply printing them out for now. I've created processes with Popen, but if I use communicate() the data comes at me all at once, once the process has terminated. If I create a separate thread that does a blocking readline() of myprocess.stdout (using stdout = subprocess.PIPE) I don't get any lines with this method either, until the process terminates. (no matter what I set as bufsize) Is there a way to deal with this that isn't horrendous, and works well on multiple platforms?
How do I get 'real-time' information back from a subprocess.Popen in python (2.5)
0.019997
0
0
13,436
874,815
2009-05-17T15:20:00.000
7
0
0
1
python,subprocess,stdout,popen
874,865
10
false
0
0
stdout will be buffered - so you won't get anything till that buffer is filled, or the subprocess exits. You can try flushing stdout from the sub-process, or using stderr, or changing stdout on non-buffered mode.
2
47
0
I'd like to use the subprocess module in the following way: create a new process that potentially takes a long time to execute. capture stdout (or stderr, or potentially both, either together or separately) Process data from the subprocess as it comes in, perhaps firing events on every line received (in wxPython say) or simply printing them out for now. I've created processes with Popen, but if I use communicate() the data comes at me all at once, once the process has terminated. If I create a separate thread that does a blocking readline() of myprocess.stdout (using stdout = subprocess.PIPE) I don't get any lines with this method either, until the process terminates. (no matter what I set as bufsize) Is there a way to deal with this that isn't horrendous, and works well on multiple platforms?
How do I get 'real-time' information back from a subprocess.Popen in python (2.5)
1
0
0
13,436
874,856
2009-05-17T15:45:00.000
0
0
0
0
python,import,wxpython
875,039
3
false
0
1
You could create a global boolean variable like g_window_was_drawn and check it in the function that does the work of creating a window. The value would be false at the start of the program and would change to True when first creating a window. The function that creates the window would check if the g_window_was_drawn is already true, and if it is, it would throw an exception. Then You will have a nice stacktrace telling You who is responsible of executing this function. I hope that helps You find it. I'm sorry for the verbal solution ;)
1
0
0
I'm sorry for the verbal description. I have a wxPython app in a file called applicationwindow.py that resides in a package called garlicsimwx. When I launch the app by launching the aforementioned file, it all works well. However, I have created a file rundemo.py in a folder which contains the garlicsimwx package, which runs the app as well. When I use rundemo.py, the app launches, however, when the main wx.Frame imports a sub-package of garlicsimwx, namely simulations.life, for some reason a new instance of my application is created (i.e., a new identical window pops out.) I have tried stepping through the commands one-by-one, and although the bug happens only after importing the sub-package, the import statement doesn't directly cause it. Only when control returns to PyApp.MainLoop the second window opens. How do I stop this?
wxPython launches my app twice when importing a sub-package
0
0
0
223