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
3,701,646
2010-09-13T15:04:00.000
2
0
0
1
python,windows,environment-variables,pythonpath
13,650,817
22
false
1
0
This PYTHONPATH variable needs to be set for ArcPY when ArcGIS Desktop is installed. PYTHONPATH=C:\arcgis\bin (your ArcGIS home bin) For some reason it never was set when I used the installer on a Windows 7 32-bit system.
5
435
0
I have a directory which hosts all of my Django apps (C:\My_Projects). I want to add this directory to my PYTHONPATH so I can call the apps directly. I tried adding C:\My_Projects\; to my Windows Path variable from the Windows GUI (My Computer > Properties > Advanced System Settings > Environment Variables). But it still doesn't read the coltrane module and generates this error: Error: No module named coltrane
How to add to the PYTHONPATH in Windows, so it finds my modules/packages?
0.01818
0
0
1,708,519
3,701,646
2010-09-13T15:04:00.000
6
0
0
1
python,windows,environment-variables,pythonpath
38,088,508
22
false
1
0
The python 2.X paths can be set from few of the above instructions. Python 3 by default will be installed in C:\Users\\AppData\Local\Programs\Python\Python35-32\ So this path has to be added to Path variable in windows environment.
5
435
0
I have a directory which hosts all of my Django apps (C:\My_Projects). I want to add this directory to my PYTHONPATH so I can call the apps directly. I tried adding C:\My_Projects\; to my Windows Path variable from the Windows GUI (My Computer > Properties > Advanced System Settings > Environment Variables). But it still doesn't read the coltrane module and generates this error: Error: No module named coltrane
How to add to the PYTHONPATH in Windows, so it finds my modules/packages?
1
0
0
1,708,519
3,701,646
2010-09-13T15:04:00.000
61
0
0
1
python,windows,environment-variables,pythonpath
14,753,412
22
false
1
0
Just append your installation path (ex. C:\Python27\) to the PATH variable in System variables. Then close and open your command line and type 'python'.
5
435
0
I have a directory which hosts all of my Django apps (C:\My_Projects). I want to add this directory to my PYTHONPATH so I can call the apps directly. I tried adding C:\My_Projects\; to my Windows Path variable from the Windows GUI (My Computer > Properties > Advanced System Settings > Environment Variables). But it still doesn't read the coltrane module and generates this error: Error: No module named coltrane
How to add to the PYTHONPATH in Windows, so it finds my modules/packages?
1
0
0
1,708,519
3,701,646
2010-09-13T15:04:00.000
1
0
0
1
python,windows,environment-variables,pythonpath
58,418,095
22
false
1
0
While this question is about the 'real' Python, it did come up in a websearch for 'Iron Python PYTHONPATH'. For Iron Python users as confused as I was: It turns out that Iron Python looks for an environment variable called IRONPYTHONPATH. Linux/Mac/POSIX users: Don't forget that not only does Windows use \ as path separators, but it also uses ; as path delimiters, not :.
5
435
0
I have a directory which hosts all of my Django apps (C:\My_Projects). I want to add this directory to my PYTHONPATH so I can call the apps directly. I tried adding C:\My_Projects\; to my Windows Path variable from the Windows GUI (My Computer > Properties > Advanced System Settings > Environment Variables). But it still doesn't read the coltrane module and generates this error: Error: No module named coltrane
How to add to the PYTHONPATH in Windows, so it finds my modules/packages?
0.009091
0
0
1,708,519
3,702,724
2010-09-13T17:09:00.000
1
1
0
0
php,python,cakephp
3,702,748
3
false
0
0
First of all, check what kinds of syndication CakePHP offers. It may expose part of its API through xmlrpc, json, RSS, and so on. If that's not an option, connect directly to the same database the CakePHP application uses. Or alternatively, implement some php code within your CakePHP framework that expors relevant data as JSON and interface with it.
1
0
0
I have a webapp, created using CakePhp. I need to interface with a Python script. What is the best way to go about doing that? (I could use pipe etc., but I want to check what the best practices are) Thanks.
Php/Cakephp interface with Python script
0.066568
0
0
1,320
3,702,889
2010-09-13T17:32:00.000
0
1
0
0
python,emacs,textmate,environment
3,703,093
4
false
0
0
Use Command-R to run the script directly Use Shift-Command-R to run the script from terminal.
2
0
0
I use TextMate to debug python script, as I like the feature of using 'Command-R' for running python from TextMate, and I learned that emacs provide similar feature. I need to know if the python is run from command line or from TextMate/emacs. How can I do that? ADDED I use TextMate for python coding/debugging, and it's pretty useful. But, sometimes I need to run the test using command line. I normally turn on debugging/logging mode with TextMate, and off with command line mode. This is the reason I asked the question. Also, I plan to use emacs for python debugging, so I wanted to ask the case for emacs. I got an answer in the case with emacs, and I happen to solve this issue with TextMate. Set variables in Preferences -> Advanced -> Shell Variables, and I found that TM_ORGANIZATION_NAME is already there to be used. So, I'll just use this variable. Use this variable, if os.environ['TM_ORGANIZATION_NAME']: return True I guess the shell variable from TextMate disappear when I'm done using it.
How to know if I run python from Textmate/emacs?
0
0
0
521
3,702,889
2010-09-13T17:32:00.000
1
1
0
0
python,emacs,textmate,environment
3,702,945
4
false
0
0
sys.argv will tell you how Python was invoked. I don't know about TextMate, but when I tell Emacs to eval buffer, its value is ['-c']. That means it's executing a specified command, according to the man page. If Python's run directly from the command line with no parameters, sys.argv will be []. If you run a python script, it will have the script name and whatever arguments you pass it. You might want to set up your python-mode in Emacs and whatever the equivalent in TextMate is to put something special like -t in the command line. That's pretty hackish though. Maybe there's a better way.
2
0
0
I use TextMate to debug python script, as I like the feature of using 'Command-R' for running python from TextMate, and I learned that emacs provide similar feature. I need to know if the python is run from command line or from TextMate/emacs. How can I do that? ADDED I use TextMate for python coding/debugging, and it's pretty useful. But, sometimes I need to run the test using command line. I normally turn on debugging/logging mode with TextMate, and off with command line mode. This is the reason I asked the question. Also, I plan to use emacs for python debugging, so I wanted to ask the case for emacs. I got an answer in the case with emacs, and I happen to solve this issue with TextMate. Set variables in Preferences -> Advanced -> Shell Variables, and I found that TM_ORGANIZATION_NAME is already there to be used. So, I'll just use this variable. Use this variable, if os.environ['TM_ORGANIZATION_NAME']: return True I guess the shell variable from TextMate disappear when I'm done using it.
How to know if I run python from Textmate/emacs?
0.049958
0
0
521
3,703,621
2010-09-13T19:17:00.000
5
1
0
0
python,security,cgi-bin
3,703,723
3
true
0
0
check out owasp.org - you're now writing a web application, and you need to worry about everything web apps need to worry about. The list is too long and complicated to place here, but owasp is a good starting point.
1
2
0
I've been writing python scripts that run locally. I would now like to offer a service online using one of these python scripts and through the webhosting I have I can run python in the cgi-bin. The python script takes input from an html form filled in by the user, has the credentials and connects with a local database, calculates stuff using python libraries and sends out the results as HTML to be displayed. What I would like to know is what security precautions I should take. Here are my worries: What are the right file permissions for scripts called via web? 755? I am taking user input. How do I guarantee it is sanitized? I have user/pass for the database in the script. How do I prevent the script from being downloaded and the code seen? Can I install the other libraries next to the file? Do I have to worry about security of/in these as well? Do I set their permissions to 700? 744? Any other vulnerability I am unaware of?
Security precautions for running python in cgi-bin
1.2
0
0
2,862
3,703,704
2010-09-13T19:29:00.000
2
1
1
0
java,python,dynamic-languages
3,703,964
3
false
0
0
Some things that struck me when first trying out Python (coming from a mainly Java background): Write Pythonic code. Use idioms recommended for Python, rather than doing it the old Java/C way. This is more than just a cosmetic or dogmatic issue. Pythonic code is actually hugely faster in practice than C-like code practically all the time. As a matter of fact, IMHO a lot of the "Python is slow" notion floating around is due to the fact that inexperienced coders tried to code Java/C in Python and ended up taking a big performance hit and got the idea that Python is horribly slow. Use list comprehensions and map/filter/reduce whenever possible. Get comfortable with the idea that functions are truly objects. Pass them around as callbacks, make functions return functions, learn about closures etc. There are a lot of cool and almost magical stuff you can do in Python like renaming methods as you mention. These things are great to show off Python's features, but really not necessary if you don't need them. Indeed, as S. Lott pointed out, its better to avoid things that seem risky.
2
6
0
What are the top gotchas for someone moving from a static lang (java/c#) to dynamic language like python? It seems cool how things can be done, but renaming a method, or adding/removing parameters seems so risky! Is the only solution to write tests for each method?
top gotchas for someone moving from a static lang (java/c#) to dynamic language like python
0.132549
0
0
248
3,703,704
2010-09-13T19:29:00.000
3
1
1
0
java,python,dynamic-languages
3,703,732
3
false
0
0
"Is the only solution to write tests for each method?" Are you saying you didn't write tests for each method in Java? If you wrote tests for each method in Java, then -- well -- nothing changes, does it? renaming a method, seems so risky! Correct. Don't do it. adding/removing parameters seems so risky! What? Are you talking about optional parameters? If so, then having multiple overloaded names in Java seems risky and confusing. Having optional parameters seems simpler. If you search on SO for the most common Python questions, you'll find that some things are chronic questions. How to update the PYTHONPATH. Why some random floating-point calculation isn't the same as a mathematical abstraction might indicate. Using Python 3 and typing code from a Python 2 tutorial. Why Python doesn't have super-complex protected, private and public declarations. Why Python doesn't have an enum type. The #1 chronic problem seems to be using mutable objects as default values for a function. Simply avoid this.
2
6
0
What are the top gotchas for someone moving from a static lang (java/c#) to dynamic language like python? It seems cool how things can be done, but renaming a method, or adding/removing parameters seems so risky! Is the only solution to write tests for each method?
top gotchas for someone moving from a static lang (java/c#) to dynamic language like python
0.197375
0
0
248
3,704,404
2010-09-13T21:03:00.000
7
0
0
0
python,django,session,django-sessions
3,704,462
1
true
1
0
Is there a good rule of thumb for which one to use? No. Cached_db seems like it would always be a better choice ... That's fine. In some cases, there a many Django (and Apache) processes querying a common database. mod_wsgi allows a lot of scalability this way. The cache doesn't help much because the sessions are distributed randomly among the Apache (and Django) processes. Is it possible to have both, the session expire at the browser close AND give an age? Don't see why not. What is considered "inactivity"? I assume you're kidding. "activity" is -- well -- activity. You know. Stuff happening in Django. A GET or POST request that Django can see. What else could it be? Where exactly would one put code to "purge the db"? Put it in crontab or something similar. I feel like you would need a seperate thread to just go through the db every once in awhile (Every hour?) Forget threads (please). It's a separate process. Once a day is fine. How many sessions do you think you'll have?
1
6
0
I'm using sessions in Django to store login user information as well as some other information. I've been reading through the Django session website and still have a few questions. From the Django website: By default, Django stores sessions in your database (using the model django.contrib.sessions.models.Session). Though this is convenient, in some setups it’s faster to store session data elsewhere, so Django can be configured to store session data on your filesystem or in your cache. Also: For persistent, cached data, set SESSION_ENGINE to django.contrib.sessions.backends.cached_db. This uses a write-through cache – every write to the cache will also be written to the database. Session reads only use the database if the data is not already in the cache. Is there a good rule of thumb for which one to use? cached_db seems like it would always be a better choice because best case, the data is in the cache, and worst case it's in the database where it would be anyway. The one downside is I have to setup memcached. By default, SESSION_EXPIRE_AT_BROWSER_CLOSE is set to False, which means session cookies will be stored in users' browsers for as long as SESSION_COOKIE_AGE. Use this if you don't want people to have to log in every time they open a browser. Is it possible to have both, the session expire at the browser close AND give an age? If value is an integer, the session will expire after that many seconds of inactivity. For example, calling request.session.set_expiry(300) would make the session expire in 5 minutes. What is considered "inactivity"? If you're using the database backend, note that session data can accumulate in the django_session database table and Django does not provide automatic purging. Therefore, it's your job to purge expired sessions on a regular basis. So that means, even if the session is expired there are still records in my database. Where exactly would one put code to "purge the db"? I feel like you would need a seperate thread to just go through the db every once in awhile (Every hour?) and delete any expired sessions.
Using sessions in Django
1.2
0
0
4,031
3,704,570
2010-09-13T21:29:00.000
20
0
0
0
python,floating-point,numerical-stability
3,704,637
4
false
0
0
Would it be possible to do your work in a logarithmic space? (For example, instead of storing 1e-320, just store -320, and use addition instead of multiplication)
1
24
1
I have a Bayesian Classifier programmed in Python, the problem is that when I multiply the features probabilities I get VERY small float values like 2.5e-320 or something like that, and suddenly it turns into 0.0. The 0.0 is obviously of no use to me since I must find the "best" class based on which class returns the MAX value (greater value). What would be the best way to deal with this? I thought about finding the exponential portion of the number (-320) and, if it goes too low, multiplying the value by 1e20 or some value like that. But maybe there is a better way?
In Python small floats tending to zero
1
0
0
17,743
3,705,421
2010-09-14T00:48:00.000
6
0
1
0
python,console,interactive
3,705,551
2
true
0
0
Run the script from the console with python -i. It will go through the commands and drop you in the usual Python console when it's done.
1
3
0
I'm looking to have the same functionality (history, ...) as when you simply type python in your terminal. The script I have goes through a bunch of setup code, and when ready, the user should have a command prompt. What would be the best way to achieve this?
Create console in python
1.2
0
0
2,213
3,706,128
2010-09-14T04:25:00.000
0
0
0
0
python,windows
5,380,835
2
false
0
0
If you are using pyhook, event.WindowName in your OnKeyboardEvent etc function contains the value xx
1
1
0
How can I get the window name? I want to make a script where I have some keyboard event, and I want it to happens only if the window name has something in the name, like, Firefox. how can I do it? the simplest way
how can I get the window name? [Python]
0
0
0
4,493
3,706,469
2010-09-14T06:07:00.000
2
0
1
0
python,regex,wildcard
3,706,506
4
true
0
0
You can't do this. What should prefix.* match? What about somefiles?? These have very different meanings in regex vs glob matching, but are common use cases in both.
2
1
0
I have a python script that reads from a config file. The config file is going to contain some user defined regex patterns. However, I was thinking I'd like to let the user use either full regex patterns, OR shell wildcards. So I should be able to interpret both *.txt as well as .*\.txt$ correctly. So those 2 should be equivalent. However I'd like to be able to do this without making the user tell me which they're using. Is this even possible? Maybe allowing full regex is overkill.
Mixing regex and shell wildcards
1.2
0
0
534
3,706,469
2010-09-14T06:07:00.000
0
0
1
0
python,regex,wildcard
3,706,626
4
false
0
0
Try not to leave the creation of regex to the user. The user should have an easier means to configure their files without needing to use regex. Eg let the users have a few choices, starts with ends with contains (OR and AND) etc Then as the programmer, you use these choices to construct your regex.
2
1
0
I have a python script that reads from a config file. The config file is going to contain some user defined regex patterns. However, I was thinking I'd like to let the user use either full regex patterns, OR shell wildcards. So I should be able to interpret both *.txt as well as .*\.txt$ correctly. So those 2 should be equivalent. However I'd like to be able to do this without making the user tell me which they're using. Is this even possible? Maybe allowing full regex is overkill.
Mixing regex and shell wildcards
0
0
0
534
3,706,553
2010-09-14T06:27:00.000
1
0
1
0
python,list,tuples
3,706,578
5
false
0
0
I wouldn't worry about the overhead of first creating a list and then a tuple from that list. My guess is that the overhead will turn out to be negligible if you measure it. On the other hand, I would stick with the list and iterate over that instead of creating a tuple. Tuples should be used for struct like data and list for lists of data, which is what your data sounds like to me.
2
2
0
I have a config file that contains a list of strings. I need to read these strings in order and store them in memory and I'm going to be iterating over them many times when certain events take place. Since once they're read from the file I don't need to add or modify the list, a tuple seems like the most appropriate data structure. However, I'm a little confused on the best way to first construct the tuple since it's immutable. Should I parse them into a list then put them in a tuple? Is that wasteful? Is there a way to get them into a tuple first without the overhead of copying/destroying the tuple every time I add a new element.
Parsing indeterminate amount of data into a python tuple
0.039979
0
0
196
3,706,553
2010-09-14T06:27:00.000
2
0
1
0
python,list,tuples
3,706,568
5
false
0
0
As you said, you're going to read the data gradually - so a tuple isn't a good idea after all, as it's immutable. Is there a reason for not using a simple list for holding the strings?
2
2
0
I have a config file that contains a list of strings. I need to read these strings in order and store them in memory and I'm going to be iterating over them many times when certain events take place. Since once they're read from the file I don't need to add or modify the list, a tuple seems like the most appropriate data structure. However, I'm a little confused on the best way to first construct the tuple since it's immutable. Should I parse them into a list then put them in a tuple? Is that wasteful? Is there a way to get them into a tuple first without the overhead of copying/destroying the tuple every time I add a new element.
Parsing indeterminate amount of data into a python tuple
0.07983
0
0
196
3,709,094
2010-09-14T13:01:00.000
1
0
0
0
python,django
9,905,973
3
false
1
0
My company did just build such a system for a large scale enterprise based on Django including all mobile systems. With django the dev cost were low and runnability inside enterprise server stack was no problem. Even Django managed to let us pass the penetration and security test. with any other language we would not have been able to succeed with this project under extrem budget restrictions
2
2
0
I wanted to know is Django a good choice for a big web applicatin(Social Network)? More specifically, I need some suggestion on performace when number of DB transactions increases and I want to know is the embedded OR Mapping included inside Django is a good choice or should I implement them. Thanks
Django for enterprise web application
0.066568
0
0
2,228
3,709,094
2010-09-14T13:01:00.000
5
0
0
0
python,django
3,710,103
3
true
1
0
performace when number of DB transactions increases. Not a Django problem, really. You can have a lot of concurrent Django sessions via Apache and mod_wsgi. All of them will share a common database. Therefore, this is entirely a database problem. You should be able to configure enough Apache/Django sessions that your database is swamped. OR Mapping included inside Django is a good choice or should I implement them. Yes. It's a really good choice. Until you can prove that the ORM is your bottleneck, use it. As you scale up, you will rework your database, your cache, and other architectural features. Since the ORM has a cache (as does your database), you rarely have performance issues here. You can. But most of your performance problems will be downloading static media files through Apache.
2
2
0
I wanted to know is Django a good choice for a big web applicatin(Social Network)? More specifically, I need some suggestion on performace when number of DB transactions increases and I want to know is the embedded OR Mapping included inside Django is a good choice or should I implement them. Thanks
Django for enterprise web application
1.2
0
0
2,228
3,710,751
2010-09-14T16:13:00.000
1
0
0
0
python,wxpython
3,716,517
3
false
0
1
We should bind wx.EVT_TEXT_COPY and wx.EVT_TEXT_PASTE with text control. one can copy and paste data from text ctrl although text ctrl is read only mode.
1
1
0
In my application i have text control. I want my text ctrl should be read only but when some one right click on this he is able to copy the value from that ctrl and he can paste that value in other text control. If i made my text control read only with wx.TE_READONLY then copy/paste is not working. Is there any requirement to handle other type of wx event or i have to set more type of wx style flags while creating the text control object. Thanks in advance.
how to create read only text ctrl but support copy paste event
0.066568
0
0
8,427
3,711,762
2010-09-14T18:22:00.000
0
0
1
0
python
3,716,937
2
false
0
0
To convert a number to a list of it's binary digits: list(bin(number))[2:]
1
0
0
hi i am new in python just started learning with python i got a task in which i need to store "1" byte of integer into different bits just like RGB the value are store in that can any one would write a small program for me and explain that ,please i need a help Thankyou
python bitwise operation
0
0
0
1,075
3,712,125
2010-09-14T19:16:00.000
2
1
1
0
c++,python,boost-python
3,712,249
3
false
0
1
C++ can interoperate with C by extern "C" declarations.
1
8
0
How is Python able to call C++ objects when the interpreter is C and has been built w/ a C compiler?
How does Boost.Python work?
0.132549
0
0
1,508
3,712,885
2010-09-14T21:03:00.000
0
1
0
0
python,module,attributes,return
3,713,156
5
false
0
0
dir is what you need :)
1
1
0
I already search for it on Google but I didn't have luck.
Does Python have a method that returns all the attributes in a module?
0
0
0
282
3,712,949
2010-09-14T21:11:00.000
2
0
0
0
python,sqlalchemy,primary-key
3,713,061
3
true
0
0
I always make surrogate keys when using ORMs (or rather, I let the ORMs make them for me). They solve a number of problems, and don't introduce any (major) problems. So, you've done your job by acknowledging that there are "papers on the net" with valid reasons to avoid surrogate keys, and that there's probably a better way to do it. Now, write "# TODO: find a way to avoid surrogate keys" somewhere in your source code and go get some work done.
3
2
0
Short story I have a technical problem with a third-party library at my hands that I seem to be unable to easily solve in a way other than creating a surrogate key (despite the fact that I'll never need it). I've read a number of articles on the Net discouraging the use of surrogate keys, and I'm a bit at a loss if it is okay to do what I intend to do. Long story I need to specify a primary key, because I use SQLAlchemy ORM (which requires one), and I cannot just set it in __mapper_args__, since the class is being built with classobj, and I have yet to find a way to reference the field of a not-yet-existing class in the appropriate PK definition argument. Another problem is that the natural equivalent of the PK is a composite key that is too long for the version of MySQL I use (and it's generally a bad idea to use such long primary keys anyway).
How badly should I avoid surrogate primary keys in SQL?
1.2
1
0
698
3,712,949
2010-09-14T21:11:00.000
0
0
0
0
python,sqlalchemy,primary-key
4,160,811
3
false
0
0
I use surrogate keys in a db that I use reflection on with sqlalchemy. The pro is that you can more easily manage the foreign keys / relationships that exists in your tables / models. Also, the rdbms is managing the data more efficiently. The con is the data inconsistency: duplicates. To avoid this - always use the unique constraint on your natural key. Now, I understand from your long story that you can't enforce this uniqueness because of your mysql limitations. For long composite keys mysql causes problems. I suggest you move to postgresql.
3
2
0
Short story I have a technical problem with a third-party library at my hands that I seem to be unable to easily solve in a way other than creating a surrogate key (despite the fact that I'll never need it). I've read a number of articles on the Net discouraging the use of surrogate keys, and I'm a bit at a loss if it is okay to do what I intend to do. Long story I need to specify a primary key, because I use SQLAlchemy ORM (which requires one), and I cannot just set it in __mapper_args__, since the class is being built with classobj, and I have yet to find a way to reference the field of a not-yet-existing class in the appropriate PK definition argument. Another problem is that the natural equivalent of the PK is a composite key that is too long for the version of MySQL I use (and it's generally a bad idea to use such long primary keys anyway).
How badly should I avoid surrogate primary keys in SQL?
0
1
0
698
3,712,949
2010-09-14T21:11:00.000
0
0
0
0
python,sqlalchemy,primary-key
3,713,270
3
false
0
0
"Using a surrogate key allows duplicates to be created when using a natural key would have prevented such problems" Exactly, so you should have both keys, not just a surrogate. The error you seem to be making is not that you are using a surrogate, it's that you are assuming the table only needs one key. Make sure you create all the keys you need to ensure the integrity of your data. Having said that, in this case it seems like a deficiency of the ORM software (apparently not being able to use a composite key) is the real cause of your problems. It's unfortunate that a software limitation like that should force you to create keys you don't otherwise need. Maybe you could consider using different software.
3
2
0
Short story I have a technical problem with a third-party library at my hands that I seem to be unable to easily solve in a way other than creating a surrogate key (despite the fact that I'll never need it). I've read a number of articles on the Net discouraging the use of surrogate keys, and I'm a bit at a loss if it is okay to do what I intend to do. Long story I need to specify a primary key, because I use SQLAlchemy ORM (which requires one), and I cannot just set it in __mapper_args__, since the class is being built with classobj, and I have yet to find a way to reference the field of a not-yet-existing class in the appropriate PK definition argument. Another problem is that the natural equivalent of the PK is a composite key that is too long for the version of MySQL I use (and it's generally a bad idea to use such long primary keys anyway).
How badly should I avoid surrogate primary keys in SQL?
0
1
0
698
3,712,992
2010-09-14T21:17:00.000
0
0
0
1
python,windows
3,954,806
2
true
0
0
I had to use remote registry... HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion ProductName, EditionID, CurrentVersion, CurrentBuild
1
1
0
So of course I'm new to Python and to programming in general... I am trying to get OS version information from the network. For now I only care about the windows machines. using PyWin32 I can get some basic information, but it's not very reliable. This is an example of what I am doing right now: win32net.NetWkstaGetInfo(myip, 100) However, it appears as though this would provide me with more appropriate information: platform.win32_ver() I have no idea how get the info from a remote machine using this. I need to specify an IP or a range of IP's... I intend on using Google's ipaddr to get a list of network ranges to scan. I will eventually need to scan a large network for this info. Can someone provide an example?
Python: How to use platform.win32_ver() on a remote machine?
1.2
0
0
1,156
3,714,613
2010-09-15T04:12:00.000
3
0
1
0
python,thread-safety
3,716,794
5
false
0
1
In normal python this will be safe as all access to variables are protected by the GIL(Global Interpreter Lock) this means that all access to a variable are syncronised so only one thread can do this at a time. The only issue is as @Eloff noted if you need to read more than one value and need them to be consistent - you will need to design in some control of access in this case.
5
6
0
I have a Python/wxPython program where the GUI is the main thread and I use another thread to load data from a file. Sometimes the files are big and slow to load so I use a wxPulse dialog to indicate progress. As I load the file, I count the number of lines that have been read in the counting thread, and I display this count in the wxPulse dialog in the main thread. I get the count in the main thread by reading the same variable that is being written to by the loading thread. Is this "thread safe"? Could this somehow cause problems? I've been doing it for awhile and it has been fine so far. PS. I know I could use a queue to transfer the count, but I'm lazy and don't want to if I don't have to.
Python: safe to read values from an object in a thread?
0.119427
0
0
2,094
3,714,613
2010-09-15T04:12:00.000
1
0
1
0
python,thread-safety
3,714,773
5
false
0
1
It's quite safe. When the count increases from n to n+1 the "n+1 object" is created and then count is switched from referring to the "n object" to the new "n+1 object". There is no stage that count is referring to something other than the "n object" or the "n+1 object"
5
6
0
I have a Python/wxPython program where the GUI is the main thread and I use another thread to load data from a file. Sometimes the files are big and slow to load so I use a wxPulse dialog to indicate progress. As I load the file, I count the number of lines that have been read in the counting thread, and I display this count in the wxPulse dialog in the main thread. I get the count in the main thread by reading the same variable that is being written to by the loading thread. Is this "thread safe"? Could this somehow cause problems? I've been doing it for awhile and it has been fine so far. PS. I know I could use a queue to transfer the count, but I'm lazy and don't want to if I don't have to.
Python: safe to read values from an object in a thread?
0.039979
0
0
2,094
3,714,613
2010-09-15T04:12:00.000
8
0
1
0
python,thread-safety
3,714,627
5
true
0
1
Generally as long as... You only have one thread writing to it, and... It's not important that the count be kept precisely in sync with the displayed value... it's fine.
5
6
0
I have a Python/wxPython program where the GUI is the main thread and I use another thread to load data from a file. Sometimes the files are big and slow to load so I use a wxPulse dialog to indicate progress. As I load the file, I count the number of lines that have been read in the counting thread, and I display this count in the wxPulse dialog in the main thread. I get the count in the main thread by reading the same variable that is being written to by the loading thread. Is this "thread safe"? Could this somehow cause problems? I've been doing it for awhile and it has been fine so far. PS. I know I could use a queue to transfer the count, but I'm lazy and don't want to if I don't have to.
Python: safe to read values from an object in a thread?
1.2
0
0
2,094
3,714,613
2010-09-15T04:12:00.000
2
0
1
0
python,thread-safety
3,714,663
5
false
0
1
This is fine because you have only one writer thread. Read only operations are always thread-safe. The exception to this arises when you are reading more than one related value and expecting some form of consistency between them. Since writes can happen at any time, reads of multiple values may not be consistent and indeed may not even have any sensible program state at all. In this case, locks are used to make the multiple reads appear to happen as a single atomic operation exclusive to any writes.
5
6
0
I have a Python/wxPython program where the GUI is the main thread and I use another thread to load data from a file. Sometimes the files are big and slow to load so I use a wxPulse dialog to indicate progress. As I load the file, I count the number of lines that have been read in the counting thread, and I display this count in the wxPulse dialog in the main thread. I get the count in the main thread by reading the same variable that is being written to by the loading thread. Is this "thread safe"? Could this somehow cause problems? I've been doing it for awhile and it has been fine so far. PS. I know I could use a queue to transfer the count, but I'm lazy and don't want to if I don't have to.
Python: safe to read values from an object in a thread?
0.07983
0
0
2,094
3,714,613
2010-09-15T04:12:00.000
0
0
1
0
python,thread-safety
3,714,667
5
false
0
1
It's safe only because it's not especially critical. Weird things like the value not updating when it should won't matter. It is very hard to get a definitive answer on what happens when you pretend a single int that's being read and written to is "atomic", as it depends on the exact architecture and a bunch of other things. But it won't do anything worse than give the wrong number sometimes, so go ahead... or use a queue. :)
5
6
0
I have a Python/wxPython program where the GUI is the main thread and I use another thread to load data from a file. Sometimes the files are big and slow to load so I use a wxPulse dialog to indicate progress. As I load the file, I count the number of lines that have been read in the counting thread, and I display this count in the wxPulse dialog in the main thread. I get the count in the main thread by reading the same variable that is being written to by the loading thread. Is this "thread safe"? Could this somehow cause problems? I've been doing it for awhile and it has been fine so far. PS. I know I could use a queue to transfer the count, but I'm lazy and don't want to if I don't have to.
Python: safe to read values from an object in a thread?
0
0
0
2,094
3,715,244
2010-09-15T06:40:00.000
1
0
1
0
python
3,715,512
4
false
0
0
There is no need to base64 encode the string, just paste it's repr into the code
2
5
0
Instead of using directories to reference an image, is it possible to code an image into the program directly?
Is it possible to code images into a python script?
0.049958
0
0
9,239
3,715,244
2010-09-15T06:40:00.000
0
0
1
0
python
3,715,291
4
false
0
0
If you mean, storing the bytes that represent the image in the program code itself, you could do it by base64 encoding the image file, and setting a variable to that string. You could also declare a byte array, where the contents of the array are the bytes that represent the image. In both cases, if you want to operate on the image, you may need to decode the value that you have included in your source code. Warning: you may be treading on a performance minefield here. A better way might be to store the image/s in the directory structure of your module, and the loading it on demand (even caching it). You could write a generalized method/function that loads the right image based on some identifier which maps to the particular image file name that is part and parcel of your module.
2
5
0
Instead of using directories to reference an image, is it possible to code an image into the program directly?
Is it possible to code images into a python script?
0
0
0
9,239
3,715,317
2010-09-15T06:53:00.000
1
0
0
0
python,user-interface,wxpython
3,716,150
1
false
0
1
Not built in. You'd have to create your own.
1
0
0
A wxPython program that I'm writing uses two sliders as part of the GUI. These sliders represent a three state switch with the states "On Full", "On Medium" and "Off". I'd like to be able to assign these labels to the ticks on the slider. Is there a way of doing this without having to subclass or position separate static text controls? Thanks, Spry
wxPython: Assigning text labels to ticks on a slider
0.197375
0
0
326
3,715,456
2010-09-15T07:15:00.000
3
0
0
0
python,mysql,database,database-design,postgresql
3,715,621
3
false
0
0
PostgreSQL doesn't impose a direct limit on this, your OS does (it depends on maximum directory size) This may depend on your OS as well. Some filesystems get slower with large directories. PostgreSQL won't be able to optimize queries if they're across different tables. So using less tables (or a single table) should be more efficient
2
7
0
I have created a database in PostgreSQL, let's call it testdb. I have a generic set of tables inside this database, xxx_table_one, xxx_table_two and xxx_table_three. Now, I have Python code where I want to dynamically create and remove "sets" of these 3 tables to my database with a unique identifier in the table name distinguishing different "sets" from each other, e.g. Set 1 testdb.aaa_table_one testdb.aaa_table_two testdb.aaa_table_three Set 2 testdb.bbb_table_one testdb.bbb_table_two testdb.bbb_table_three The reason I want to do it this way is to keep multiple LARGE data collections of related data separate from each other. I need to regularly overwrite individual data collections, and it's easy if we can just drop the data collections table and recreate a complete new set of tables. Also, I have to mention, the different data collections fit into the same schemas, so I could save all the data collections in 1 set of tables using an identifier to distinguish data collections instead of separating them by using different tables. I want to know, a few things Does PostgreSQL limit the number of tables per database? What is the effect on performance, if any, of having a large number of tables in 1 database? What is the effect on performance of saving the data collections in different sets of tables compared to saving them all in the same set, e.g. I guess would need to write more queries if I want to query multiple data collections at once when the data is spread accross tables as compared to just 1 set of tables.
Is there a limitation on the number of tables a PostgreSQL database can have?
0.197375
1
0
5,102
3,715,456
2010-09-15T07:15:00.000
0
0
0
0
python,mysql,database,database-design,postgresql
5,603,789
3
false
0
0
If your data were not related, I think your tables could be in different schema, and then you would use SET search_path TO schema1, public for example, this way you wouldn't have to dynamically generate table names in your queries. I am planning to try this structure on a large database which stores logs and other tracking information. You can also change your tablespace if your os has a limit or suffers from large directory size.
2
7
0
I have created a database in PostgreSQL, let's call it testdb. I have a generic set of tables inside this database, xxx_table_one, xxx_table_two and xxx_table_three. Now, I have Python code where I want to dynamically create and remove "sets" of these 3 tables to my database with a unique identifier in the table name distinguishing different "sets" from each other, e.g. Set 1 testdb.aaa_table_one testdb.aaa_table_two testdb.aaa_table_three Set 2 testdb.bbb_table_one testdb.bbb_table_two testdb.bbb_table_three The reason I want to do it this way is to keep multiple LARGE data collections of related data separate from each other. I need to regularly overwrite individual data collections, and it's easy if we can just drop the data collections table and recreate a complete new set of tables. Also, I have to mention, the different data collections fit into the same schemas, so I could save all the data collections in 1 set of tables using an identifier to distinguish data collections instead of separating them by using different tables. I want to know, a few things Does PostgreSQL limit the number of tables per database? What is the effect on performance, if any, of having a large number of tables in 1 database? What is the effect on performance of saving the data collections in different sets of tables compared to saving them all in the same set, e.g. I guess would need to write more queries if I want to query multiple data collections at once when the data is spread accross tables as compared to just 1 set of tables.
Is there a limitation on the number of tables a PostgreSQL database can have?
0
1
0
5,102
3,716,325
2010-09-15T09:27:00.000
20
0
1
1
python,file,unix,atomic
3,716,361
1
true
0
0
It is not atomic if the files are on different filsystems. In that case, python opens the source and destination file, loops on reading from the source and writing to the desination and finally unlinks the source file. If the source and destination file are on the same file system, python uses the rename() C call, which is atomic.
1
19
0
I am wondering whether python's shutil.move is atomic on linux ? Is the behavior different if the source and destination files are on two different partitions or is it same as when they are present on the same partition ? I am more concerned to know whether the shutil.move is atomic if the source and destination files are on the same partition !
Is python's shutil.move() atomic on linux?
1.2
0
0
4,324
3,717,785
2010-09-15T12:57:00.000
0
0
1
0
python,csv
3,718,100
4
false
0
0
use the int() function to covert the boolean to their int values and then store those. that being said, eli-bendersky's comment above is worth noting.
1
11
0
If I store a boolean value using the CSV module, it gets converted to the strings True or False by the str() function. However, when I load those values, a string of False evaluates to being True because it's a non-empty string. I can work around it by manually checking the string at read time with an IF statement to see what the string is, but it's somewhat less than elegant. Any better ideas, or is this just one of those things in the programming world?
What is a convenient way to store and retrieve boolean values in a CSV file
0
0
0
17,168
3,718,077
2010-09-15T13:31:00.000
-2
0
0
0
python,django,django-admin
28,936,398
5
false
1
0
I just simply Removed all currently installed versions of Django. Then freshly install the latest version of Django and it works
3
65
0
I created a little app a while ago. I created admin.py and used admin.site.register(MenuEntry) to add the class to admin console. It showed the items of that class just fine. Then I began working on another app and created everything as before. But now it says: You don't have permission to edit anything. I compared files from that and from this apps and they look quite similar, so I just can't find the difference and I can't realize what to do now to make it work.
Django. You don't have permission to edit anything
-0.07983
0
0
20,078
3,718,077
2010-09-15T13:31:00.000
2
0
0
0
python,django,django-admin
16,760,228
5
false
1
0
I had another case where this happened. I had an app called "transcription", with two models: Project and Recording. After getting it mostly developed I decided to rename the app "recordings". The admin app worked fine as the admin but any non-admin user got this error message. Eventually I found (in my sqlite db) the table django_content_type. It had these records: id name app_label model ------------------------------------- 8 project transcription project 9 recording transcription recording 10 project recording project 11 recording recordings recording Somewhere along the way I had managed to add two (almost - don't know why "recording" in record 10) correct records while leaving the now incorrect records intact. The admin user worked just fine (I wonder why), but any other group got the error. When I looked at auth_group_permissions I saw that only records 8 and 9 were being assigned and of course there was no longer an app called "transcription". Hence the error. I deleted records 10 and 11 and changed the app_labels of 8 and 9 to "recordings" and there's joy in Mudville.
3
65
0
I created a little app a while ago. I created admin.py and used admin.site.register(MenuEntry) to add the class to admin console. It showed the items of that class just fine. Then I began working on another app and created everything as before. But now it says: You don't have permission to edit anything. I compared files from that and from this apps and they look quite similar, so I just can't find the difference and I can't realize what to do now to make it work.
Django. You don't have permission to edit anything
0.07983
0
0
20,078
3,718,077
2010-09-15T13:31:00.000
136
0
0
0
python,django,django-admin
3,718,260
5
true
1
0
I checked files one more time and found the difference. I forgot to add admin.autodiscover() in urls.py of the project. Thanks.
3
65
0
I created a little app a while ago. I created admin.py and used admin.site.register(MenuEntry) to add the class to admin console. It showed the items of that class just fine. Then I began working on another app and created everything as before. But now it says: You don't have permission to edit anything. I compared files from that and from this apps and they look quite similar, so I just can't find the difference and I can't realize what to do now to make it work.
Django. You don't have permission to edit anything
1.2
0
0
20,078
3,718,304
2010-09-15T13:54:00.000
2
1
1
0
c++,python,text
3,718,792
7
false
0
0
On the Python side the string class' translate function is the way to go. On the C++ side I would go with a std::map to hold the character mapping. Then I would probably use std::for_each to do the look up and swap.
1
3
0
As a hobby project, I had like to implement a Morse code encoder and decoder in C++ and Python (both). I was wondering the right data structure I should use for that. Not only is this question related to this specific project, but in general, when one has to make predefined text replacements, what is the best and the fastest way of doing it? I would avoid re-inventing any data structure if possible (and I think it is). Please note that this is purely a learning exercise and I have always wondered what would be the best way of doing this. I can store the code and the corresponding character in a dictionary perhaps, then iterate over the text and make replacements. Is this the best way of doing this or can I do better?
Predefined text replacements in C++ and Python
0.057081
0
0
265
3,718,322
2010-09-15T13:56:00.000
1
0
1
0
python
3,718,337
3
false
0
0
use %%..........
1
1
0
I am trying to pass a string which has a '%' in it (its actually a sql query string). How do I pass the % (do I have to use a specific escape character? eg: compute_answertime("%how do I%")
What is the escape character for % in python's string method
0.066568
0
0
179
3,718,657
2010-09-15T14:34:00.000
5
1
0
1
python
6,236,300
16
false
0
0
Just use os.path.dirname(os.path.abspath(__file__)) and examine very carefully whether there is a real need for the case where exec is used. It could be a sign of troubled design if you are not able to use your script as a module. Keep in mind Zen of Python #8, and if you believe there is a good argument for a use-case where it must work for exec, then please let us know some more details about the background of the problem.
1
358
0
I would like to see what is the best way to determine the current script directory in Python. I discovered that, due to the many ways of calling Python code, it is hard to find a good solution. Here are some problems: __file__ is not defined if the script is executed with exec, execfile __module__ is defined only in modules Use cases: ./myfile.py python myfile.py ./somedir/myfile.py python somedir/myfile.py execfile('myfile.py') (from another script, that can be located in another directory and that can have another current directory. I know that there is no perfect solution, but I'm looking for the best approach that solves most of the cases. The most used approach is os.path.dirname(os.path.abspath(__file__)) but this really doesn't work if you execute the script from another one with exec(). Warning Any solution that uses current directory will fail, this can be different based on the way the script is called or it can be changed inside the running script.
How do you properly determine the current script directory?
0.062419
0
0
156,322
3,718,695
2010-09-15T14:38:00.000
1
0
0
0
python,django,pylons
3,723,281
3
false
1
0
The ability to ask a question about it on Stackoverflow. Django has over 10,000 tagged questions, Pylon has just under 400.
2
2
0
From what I understand, Pylons is more of a 'bare bones' framework (where you can choose your ORM and template engine), and Django is a little more rich in nature. What exactly are the features/frameworky elements that Django has that Pylons doesn't? (other than its own ORM, and its auto-admin page generation)
What features does Django have that Pylons doesn't?
0.066568
0
0
401
3,718,695
2010-09-15T14:38:00.000
1
0
0
0
python,django,pylons
3,722,992
3
false
1
0
The main difference is Django's scaffolding and auto-admin interface. Both of these allow you to quickly start managing data in the website without having to create lots of views etc.
2
2
0
From what I understand, Pylons is more of a 'bare bones' framework (where you can choose your ORM and template engine), and Django is a little more rich in nature. What exactly are the features/frameworky elements that Django has that Pylons doesn't? (other than its own ORM, and its auto-admin page generation)
What features does Django have that Pylons doesn't?
0.066568
0
0
401
3,718,868
2010-09-15T14:55:00.000
12
0
1
0
python,vim,editor,cscope
3,779,871
6
true
0
0
From a correspondence with the maintainer of cscope, this tool isn't designed to work with Python, and there are no plans to implement that compatibility. Whatever works now, apparently works by mistake, and there is no promise whatsoever that it will keep working. It appears I've been using an out-of-date version of pycscope. The latest version 0.3 is supported by the cscope DB. The author of pycscope told me that he figured out the output format for the cscope DB from reading the source code of cscope. That format isn't documented, on purpose, but nevertheless it currently works with pycsope 0.3, which is the solution I'll be using. I'm going to accept this answer since unfortunately no other answer provided help even after bounty was declared. No answers are upvoted, so I honestly have no idea where the bounty will go.
1
19
0
Has anyone managed successfully using cscope with Python code? I have VIM 7.2 and the latest version of cscope installed, however it doesn't get my code's tags correctly (always off by a couple of lines). I tried the pycscope script but its output isn't supported by the modern version of cscope. Any ideas? Or an alternative for browsing Python code with VIM? (I'm specifically interested in the extra features cscope offers beyond the simple tags of ctags)
Using cscope to browse Python code with VIM?
1.2
0
0
26,659
3,719,145
2010-09-15T15:24:00.000
0
0
0
0
python,zope
3,719,408
2
false
0
0
Look at psycopg, it ships with a Zope Database Adapter.
1
3
0
I am into a project where zope web server is used. With this PostgreSQL database is used. But I am not able to add a new PostgreSQL connection via zope. Actually, I am not aware of what else I need to install so that I can use PostgreSQL dB with zope. From whatever I have explored about this I have come to know that I will require a Zope Database Adapter so that I can use PostgreSQL dB with Zope. But still I am not confirmed about this. Also I don't know which version of Zope Database Adapter will I require to install? The zope version I am using is 2.6 and PostgreSQL dB version is 7.4.13 and the Python version is 2.1.3 . Also from where should I download that Zope Database Adapter?
What are the essentials I need to install if I want to use PostgreSQL DB with zope? for eg: Zope Database Adapter?
0
1
0
110
3,721,126
2010-09-15T19:31:00.000
23
0
1
0
python,exception,assert
3,721,183
4
true
0
0
A good guideline is using assert when its triggering means a bug in your code. When your code assumes something and acts upon the assumption, it's recommended to protect this assumption with an assert. This assert failing means your assumption isn't correct, which means your code isn't correct.
2
11
0
I've read about when to use assert vs. exceptions, but I'm still not "getting it". It seems like whenever I think I'm in a situation where I should use assert, later on in development I find that I'm "looking before I leap" to make sure the assert doesn't fail when I call the function. Since there's another Python idiom about preferring to use try-except, I generally end up ditching the assert and throwing an exception instead. I have yet to find a place where it seems right to use an assert. Can anyone come up with some good examples?
Example use of assert in Python?
1.2
0
0
17,126
3,721,126
2010-09-15T19:31:00.000
3
0
1
0
python,exception,assert
3,721,144
4
false
0
0
Generelly, assert is there to verify an assumption you have about your code, i.e. at that point in time, either the assert succeeds, or your implementation is somehow buggy. An exception is acutally expecting an error to happen and "embracing" it, i.e. allowing you to handle it.
2
11
0
I've read about when to use assert vs. exceptions, but I'm still not "getting it". It seems like whenever I think I'm in a situation where I should use assert, later on in development I find that I'm "looking before I leap" to make sure the assert doesn't fail when I call the function. Since there's another Python idiom about preferring to use try-except, I generally end up ditching the assert and throwing an exception instead. I have yet to find a place where it seems right to use an assert. Can anyone come up with some good examples?
Example use of assert in Python?
0.148885
0
0
17,126
3,721,415
2010-09-15T20:11:00.000
2
1
0
0
python
3,721,515
4
true
0
0
Make sure you have the parent directory of project/ on your pythonpath, rather than the project directory. If you add the project path itself, imports like import project.src will look for project/project/src.
2
1
0
although there are many posts on the internet as well as some posts on stack overflow, I still want to ask about this nasty python "import" problem. OK. so, the open source code organization is usually like this: project/src/model.py; project/test/testmodel.py if I put the famous __init__.py in project directory and also in src/ and test/ subdirectories, and then put "from project.src import model" for the testmodel.py. it does not work! keep telling me that the Module named "project.src" is not found! how can I solve the problem without changing the code structure?
python import problem
1.2
0
0
7,796
3,721,415
2010-09-15T20:11:00.000
0
1
0
0
python
3,721,437
4
false
0
0
The directory where project is located is probably not in your python path.
2
1
0
although there are many posts on the internet as well as some posts on stack overflow, I still want to ask about this nasty python "import" problem. OK. so, the open source code organization is usually like this: project/src/model.py; project/test/testmodel.py if I put the famous __init__.py in project directory and also in src/ and test/ subdirectories, and then put "from project.src import model" for the testmodel.py. it does not work! keep telling me that the Module named "project.src" is not found! how can I solve the problem without changing the code structure?
python import problem
0
0
0
7,796
3,722,003
2010-09-15T21:33:00.000
1
1
1
0
python,c,comparison
3,722,153
6
false
0
0
As I did serious c programming I read a book that claimed libraries are worth to write. (Especially in C which considered a low level language) Libraries are build for reuse. If you use libraries you write one line like detectFace( faceDesriptor ) or renderPDF( document) is doesn't matter whether an idiom in another language is more concise or not. Lines of code isn't a proper metric if it is about what would more efficient.
5
3
0
Hi I'm currently learning Python since the syntax feels so succinct and the idioms match well with my mental model. However I'm also interested in learning about OS internals and reverse engineering software, which ultimately means knowing C in a rather thorough capacity. When originally picking a language I did lots of reading and comparisons, and it seems that a number thrown out a lot is that to write short idiomatic statements in Python would require the equivalent of a few hundred lines of C (I'd guess code for memory management, writing the code for dictionaries,lists etc) that we take for granted as built into the Python language. 1) With an average C programmer, is that 100-200 lines of code per Python idiom anywhere near accurate? Because C doesn't come built-in with Python-like constructs such as dictionaries/lists(with all their nice methods etc): 2) Do C programmers tend to build these constructs from scratch and then re-use them between projects to greatly reduce the actual amount of hand coding for their projects? I assume re-using libraries like boost:: stuff also again, reduces some of the boilerplate hand coding also... 3) But does using popular libraries and re-using common code one has written before in C for basic constructs/etc, how much does that revise the lines of code written in C compared to the code in Python of a enthusiast sized code base? I know specific numbers aren't possible, but is it possible with libraries, code reuse etc, to have a development time in C close to that of Python without being a Linus Torvalds style coding machine? Thanks!
Python vs C : Line of Code Comparison vs Dev Time
0.033321
0
0
7,636
3,722,003
2010-09-15T21:33:00.000
1
1
1
0
python,c,comparison
7,054,149
6
false
0
0
I think Python is more productive for small projects (up to a few thousand lines of code). On the other hand, C is better suited for large projects (even though IMHO there are better languages for that, such as Ada): static type-checking allows to find many errors at compile time that are much more difficult to detect at run-time, especially in a large program. In a larger C project, the lack of lists and other powerful data structures that are found in Python can be compensated by implementing or using custom libraries. I agree with user stacker that by using well-designed libraries your C code can be pretty concise.
5
3
0
Hi I'm currently learning Python since the syntax feels so succinct and the idioms match well with my mental model. However I'm also interested in learning about OS internals and reverse engineering software, which ultimately means knowing C in a rather thorough capacity. When originally picking a language I did lots of reading and comparisons, and it seems that a number thrown out a lot is that to write short idiomatic statements in Python would require the equivalent of a few hundred lines of C (I'd guess code for memory management, writing the code for dictionaries,lists etc) that we take for granted as built into the Python language. 1) With an average C programmer, is that 100-200 lines of code per Python idiom anywhere near accurate? Because C doesn't come built-in with Python-like constructs such as dictionaries/lists(with all their nice methods etc): 2) Do C programmers tend to build these constructs from scratch and then re-use them between projects to greatly reduce the actual amount of hand coding for their projects? I assume re-using libraries like boost:: stuff also again, reduces some of the boilerplate hand coding also... 3) But does using popular libraries and re-using common code one has written before in C for basic constructs/etc, how much does that revise the lines of code written in C compared to the code in Python of a enthusiast sized code base? I know specific numbers aren't possible, but is it possible with libraries, code reuse etc, to have a development time in C close to that of Python without being a Linus Torvalds style coding machine? Thanks!
Python vs C : Line of Code Comparison vs Dev Time
0.033321
0
0
7,636
3,722,003
2010-09-15T21:33:00.000
6
1
1
0
python,c,comparison
3,722,185
6
true
0
0
Boost is C++, not C (emphatically not C -- virtually all of it makes heavy use of templates and such that aren't part of C). Yes, C programmers tend to build up personal libraries of code for all sorts of "stuff" -- data structures, algorithms, user interfaces, and so on. There are also a fair number of other libraries for everything from basic string manipulation to database connectivity, user interfaces, basic algorithms and data structures, etc. Comparing productivity between the two can be difficult though -- even if something can be done in one line of code either way, there's a greater chance that the C programmer will end up doing extra work to find and learn to use that particular library. OTOH, if he has used it before, the two might be directly competitive of (in a few cases) C might be more productive. I'd guess Python ends up more productive more often, but trying to guess how much so is difficult (and lines of code usually won't be a good indication either).
5
3
0
Hi I'm currently learning Python since the syntax feels so succinct and the idioms match well with my mental model. However I'm also interested in learning about OS internals and reverse engineering software, which ultimately means knowing C in a rather thorough capacity. When originally picking a language I did lots of reading and comparisons, and it seems that a number thrown out a lot is that to write short idiomatic statements in Python would require the equivalent of a few hundred lines of C (I'd guess code for memory management, writing the code for dictionaries,lists etc) that we take for granted as built into the Python language. 1) With an average C programmer, is that 100-200 lines of code per Python idiom anywhere near accurate? Because C doesn't come built-in with Python-like constructs such as dictionaries/lists(with all their nice methods etc): 2) Do C programmers tend to build these constructs from scratch and then re-use them between projects to greatly reduce the actual amount of hand coding for their projects? I assume re-using libraries like boost:: stuff also again, reduces some of the boilerplate hand coding also... 3) But does using popular libraries and re-using common code one has written before in C for basic constructs/etc, how much does that revise the lines of code written in C compared to the code in Python of a enthusiast sized code base? I know specific numbers aren't possible, but is it possible with libraries, code reuse etc, to have a development time in C close to that of Python without being a Linus Torvalds style coding machine? Thanks!
Python vs C : Line of Code Comparison vs Dev Time
1.2
0
0
7,636
3,722,003
2010-09-15T21:33:00.000
10
1
1
0
python,c,comparison
3,722,732
6
false
0
0
but is it possible with libraries, code reuse etc, to have a development time in C close to that of Python No. You've missed the most important point. Python's interactive. It's not edit-compile-link-execute-break-debug. It's edit-debug.
5
3
0
Hi I'm currently learning Python since the syntax feels so succinct and the idioms match well with my mental model. However I'm also interested in learning about OS internals and reverse engineering software, which ultimately means knowing C in a rather thorough capacity. When originally picking a language I did lots of reading and comparisons, and it seems that a number thrown out a lot is that to write short idiomatic statements in Python would require the equivalent of a few hundred lines of C (I'd guess code for memory management, writing the code for dictionaries,lists etc) that we take for granted as built into the Python language. 1) With an average C programmer, is that 100-200 lines of code per Python idiom anywhere near accurate? Because C doesn't come built-in with Python-like constructs such as dictionaries/lists(with all their nice methods etc): 2) Do C programmers tend to build these constructs from scratch and then re-use them between projects to greatly reduce the actual amount of hand coding for their projects? I assume re-using libraries like boost:: stuff also again, reduces some of the boilerplate hand coding also... 3) But does using popular libraries and re-using common code one has written before in C for basic constructs/etc, how much does that revise the lines of code written in C compared to the code in Python of a enthusiast sized code base? I know specific numbers aren't possible, but is it possible with libraries, code reuse etc, to have a development time in C close to that of Python without being a Linus Torvalds style coding machine? Thanks!
Python vs C : Line of Code Comparison vs Dev Time
1
0
0
7,636
3,722,003
2010-09-15T21:33:00.000
0
1
1
0
python,c,comparison
3,790,500
6
false
0
0
Depends greatly on the task and the size of the project. For many small interesting tasks, I would not be surprised by 100:1 smaller Python code simply because the standard libraries are extremely good. If you find, buy, or build C/C++ libraries that do what you want, I imagine the ratio would be much more like 3:1 on big projects. However, finding, buying, and building C/C++ libraries does take time and effort, so I believe in the vast majority of cases, Python is going to be much faster to develop in.
5
3
0
Hi I'm currently learning Python since the syntax feels so succinct and the idioms match well with my mental model. However I'm also interested in learning about OS internals and reverse engineering software, which ultimately means knowing C in a rather thorough capacity. When originally picking a language I did lots of reading and comparisons, and it seems that a number thrown out a lot is that to write short idiomatic statements in Python would require the equivalent of a few hundred lines of C (I'd guess code for memory management, writing the code for dictionaries,lists etc) that we take for granted as built into the Python language. 1) With an average C programmer, is that 100-200 lines of code per Python idiom anywhere near accurate? Because C doesn't come built-in with Python-like constructs such as dictionaries/lists(with all their nice methods etc): 2) Do C programmers tend to build these constructs from scratch and then re-use them between projects to greatly reduce the actual amount of hand coding for their projects? I assume re-using libraries like boost:: stuff also again, reduces some of the boilerplate hand coding also... 3) But does using popular libraries and re-using common code one has written before in C for basic constructs/etc, how much does that revise the lines of code written in C compared to the code in Python of a enthusiast sized code base? I know specific numbers aren't possible, but is it possible with libraries, code reuse etc, to have a development time in C close to that of Python without being a Linus Torvalds style coding machine? Thanks!
Python vs C : Line of Code Comparison vs Dev Time
0
0
0
7,636
3,722,120
2010-09-15T21:49:00.000
0
0
0
0
python,mysql,django,multithreading
3,722,799
2
true
1
0
Since it mentions the character set, my gut says you are running a different Django/Python/something from the command line than you are from the webserver. In your settings file, turn on DEBUG=True, restart the server, and then run this again. In particular, look at the list of paths shown. If they are not exactly what you expect them to be, then this is a Red Flag.
1
0
0
I'm running a web crawler that gets called as a separate thread via Django. When it tries to store the scraped information I get this error: File "/usr/lib/pymodules/python2.6/MySQLdb/cursors.py", line 147, in execute charset = db.character_set_name() InterfaceError: (0, '') If I manually run the script from the command line I don't get this error. Any ideas? My guess is that I do about 4 cursor.execute()s in one iteration of a loop. Could this be throwing something off? Thanks!
mySQL interface error only occuring if ran in Django
1.2
1
0
1,854
3,724,238
2010-09-16T06:35:00.000
1
0
1
1
python,process,subprocess,parent-child
3,724,308
2
false
0
0
I guess, you are asking, how do you find if the child process is hung while operating. You can't tell easily. A process could be doing a long running operation. The context is important to understand when a process is hung. If you are expecting a process to respond to a user input and is not responsive for a long period then we consider it hung. Process is running probably waiting for some thing that will never happen. "Hung Process" is humanly way of saying that a program has reached a dead end and will be no more useful. You could have a program calculating prime numbers one after another and can run for eons and can not be called a hung process.
2
2
0
How do I know is there my child process got hang while operating?
Python subprocess how to determine if child process hangs?
0.099668
0
0
2,476
3,724,238
2010-09-16T06:35:00.000
2
0
1
1
python,process,subprocess,parent-child
3,724,322
2
true
0
0
Well, how do you tell the difference between a stuck process and a process that takes longer than usual to complete? The short answer is: No, you can't detect if your child process is stuck. I would say that to be able to detect this you need some kind of continuous communication with the process (e.g. look at log files, IPC or similar). Based on this communication you might be able to tell when and if a process is stuck.
2
2
0
How do I know is there my child process got hang while operating?
Python subprocess how to determine if child process hangs?
1.2
0
0
2,476
3,724,878
2010-09-16T08:19:00.000
1
0
0
0
php,python,frameworks,content-management-system,web-applications
3,724,889
10
false
1
0
Have you read and heard about JOOMLA i think its very poweful CMS in php and has a lot of community support as well, In java LifeRay is a good option.
6
6
0
I'm looking to build a online store. However, the first question, past the idea of the store, is the platform. I've previously worked with Java and PHP and am quite comfortable with PHP. So my first considerations were Drupal or maybe CodeIgniter (which I have heard lots of good things about) On discussions with friends, they suggested Django. But I have no experience with Python or Django. So my question is, is CI better or Drupal? And further, if not either of them, is Django better in terms of ease of development and extensibility? Request you to not make this a php vs python battle as I'm looking for advice here. Thanks Edit: More information about the project: The Project is intended to create a web-store for certain products which aren't currently sold online. The store will have high-resolution images of the products and other associated details. A few other special features related to the products will be added on in time so they aren't that important. Another clarification: I understand that Drupal is a CMS and not a framework per so. The only reason I compared it to CI was due to the base platform - php. Perhaps the better comparison would have been Joomla vs Django (but I'm not sure as I do not know enough about either, yet)
CMS or Framework?
0.019997
0
0
6,320
3,724,878
2010-09-16T08:19:00.000
-1
0
0
0
php,python,frameworks,content-management-system,web-applications
5,641,607
10
false
1
0
Yahoo has something like a specialized CMS for online stores, called Yahoo Stores. They make it very easy to set up an online store, and provide other logistical services. You may want to take a look at that. Of course, they take a small percentage from your sales.
6
6
0
I'm looking to build a online store. However, the first question, past the idea of the store, is the platform. I've previously worked with Java and PHP and am quite comfortable with PHP. So my first considerations were Drupal or maybe CodeIgniter (which I have heard lots of good things about) On discussions with friends, they suggested Django. But I have no experience with Python or Django. So my question is, is CI better or Drupal? And further, if not either of them, is Django better in terms of ease of development and extensibility? Request you to not make this a php vs python battle as I'm looking for advice here. Thanks Edit: More information about the project: The Project is intended to create a web-store for certain products which aren't currently sold online. The store will have high-resolution images of the products and other associated details. A few other special features related to the products will be added on in time so they aren't that important. Another clarification: I understand that Drupal is a CMS and not a framework per so. The only reason I compared it to CI was due to the base platform - php. Perhaps the better comparison would have been Joomla vs Django (but I'm not sure as I do not know enough about either, yet)
CMS or Framework?
-0.019997
0
0
6,320
3,724,878
2010-09-16T08:19:00.000
1
0
0
0
php,python,frameworks,content-management-system,web-applications
3,725,222
10
false
1
0
I'd only use a framework if the requirements can not be engineered into an existing cart CMS. I'd use a CMS over a shopping cart if the commerce aspect was relatively trivial I'm surprised you're not considering an off the shelf cart. Open Cart is pretty extensible, and Trading Eye has a nice CMS component.
6
6
0
I'm looking to build a online store. However, the first question, past the idea of the store, is the platform. I've previously worked with Java and PHP and am quite comfortable with PHP. So my first considerations were Drupal or maybe CodeIgniter (which I have heard lots of good things about) On discussions with friends, they suggested Django. But I have no experience with Python or Django. So my question is, is CI better or Drupal? And further, if not either of them, is Django better in terms of ease of development and extensibility? Request you to not make this a php vs python battle as I'm looking for advice here. Thanks Edit: More information about the project: The Project is intended to create a web-store for certain products which aren't currently sold online. The store will have high-resolution images of the products and other associated details. A few other special features related to the products will be added on in time so they aren't that important. Another clarification: I understand that Drupal is a CMS and not a framework per so. The only reason I compared it to CI was due to the base platform - php. Perhaps the better comparison would have been Joomla vs Django (but I'm not sure as I do not know enough about either, yet)
CMS or Framework?
0.019997
0
0
6,320
3,724,878
2010-09-16T08:19:00.000
2
0
0
0
php,python,frameworks,content-management-system,web-applications
3,725,165
10
false
1
0
If the CMS fits you perfectly now and in the future then CMS, otherwise framework. The framework will allow you total liberty for the price of time spent on development
6
6
0
I'm looking to build a online store. However, the first question, past the idea of the store, is the platform. I've previously worked with Java and PHP and am quite comfortable with PHP. So my first considerations were Drupal or maybe CodeIgniter (which I have heard lots of good things about) On discussions with friends, they suggested Django. But I have no experience with Python or Django. So my question is, is CI better or Drupal? And further, if not either of them, is Django better in terms of ease of development and extensibility? Request you to not make this a php vs python battle as I'm looking for advice here. Thanks Edit: More information about the project: The Project is intended to create a web-store for certain products which aren't currently sold online. The store will have high-resolution images of the products and other associated details. A few other special features related to the products will be added on in time so they aren't that important. Another clarification: I understand that Drupal is a CMS and not a framework per so. The only reason I compared it to CI was due to the base platform - php. Perhaps the better comparison would have been Joomla vs Django (but I'm not sure as I do not know enough about either, yet)
CMS or Framework?
0.039979
0
0
6,320
3,724,878
2010-09-16T08:19:00.000
0
0
0
0
php,python,frameworks,content-management-system,web-applications
3,724,939
10
false
1
0
Choose Django if you want to learn Python/Django and use them in your future projects. Django is cool and you'll have fun learning Python. And you'll be able to make an informed decision for your next project. However, if you have a budget/timeframe or just want to make this project out of the door without needing to learn a new framework I'd suggest choosing a tool/language you're familiar with.
6
6
0
I'm looking to build a online store. However, the first question, past the idea of the store, is the platform. I've previously worked with Java and PHP and am quite comfortable with PHP. So my first considerations were Drupal or maybe CodeIgniter (which I have heard lots of good things about) On discussions with friends, they suggested Django. But I have no experience with Python or Django. So my question is, is CI better or Drupal? And further, if not either of them, is Django better in terms of ease of development and extensibility? Request you to not make this a php vs python battle as I'm looking for advice here. Thanks Edit: More information about the project: The Project is intended to create a web-store for certain products which aren't currently sold online. The store will have high-resolution images of the products and other associated details. A few other special features related to the products will be added on in time so they aren't that important. Another clarification: I understand that Drupal is a CMS and not a framework per so. The only reason I compared it to CI was due to the base platform - php. Perhaps the better comparison would have been Joomla vs Django (but I'm not sure as I do not know enough about either, yet)
CMS or Framework?
0
0
0
6,320
3,724,878
2010-09-16T08:19:00.000
2
0
0
0
php,python,frameworks,content-management-system,web-applications
3,724,927
10
false
1
0
CI and Django are frameworks that help you build a web application from scratch, if you are willing to do this - go ahead and try it. There should be plenty of modules available that allow you to easily extend the framework. Drupal however is a CMS, so it comes with multiple plugins already installed and is able to manage your content. You'd still need to develop the "store" functionality - payment, listings, etc. - yourself.
6
6
0
I'm looking to build a online store. However, the first question, past the idea of the store, is the platform. I've previously worked with Java and PHP and am quite comfortable with PHP. So my first considerations were Drupal or maybe CodeIgniter (which I have heard lots of good things about) On discussions with friends, they suggested Django. But I have no experience with Python or Django. So my question is, is CI better or Drupal? And further, if not either of them, is Django better in terms of ease of development and extensibility? Request you to not make this a php vs python battle as I'm looking for advice here. Thanks Edit: More information about the project: The Project is intended to create a web-store for certain products which aren't currently sold online. The store will have high-resolution images of the products and other associated details. A few other special features related to the products will be added on in time so they aren't that important. Another clarification: I understand that Drupal is a CMS and not a framework per so. The only reason I compared it to CI was due to the base platform - php. Perhaps the better comparison would have been Joomla vs Django (but I'm not sure as I do not know enough about either, yet)
CMS or Framework?
0.039979
0
0
6,320
3,725,699
2010-09-16T10:19:00.000
1
0
0
0
python,database,zope
4,018,666
1
false
0
0
Yes, you can use psycopg2 with Zope2. Just install it in your Python with easy_install or setup.py. You will also need a matching ZPsycopgDA Product in Zope. You find the ZPsycopgDA folder in the psycopg2 source distribution tarball.
1
1
0
I have zope 2.11 installed. Now i want to use Posgresql 7.4.13 DB with it. So i know i need to install psycopg2 Database Adapter. Can any one tell me Is psycopg2 compatible with zope2??
Is Zpsycopg2 compatible with zope 2?
0.197375
1
0
142
3,725,859
2010-09-16T10:43:00.000
1
0
0
1
python,windows,python-3.x
3,727,415
1
false
0
0
I sounds as if you want the callee to callback the caller (sorry for the alliteration :) Since you are using Python 3.1 maybe the subprocess module will provide the intended behavior. It is not a true callback per se, but the calling program can perform decisions based on the output of the called program (exe in this case.)
1
3
0
After calling an exe using python script in windows, the exe should run independent of this python script and once it is initiated the control should comeback to python script and executes the further script and control of .py file will die. But on other side before finishing execution, the exe should call this python script. Ideas would be highly appreciated. I have tried following commands: os.system("start test.exe") os.startfile("test.exe") os.spawnlv(os.P_NOWAIT, "test.exe") os.spawnv(os.P_NOWAIT, 'C:\Python31\python.exe', ('python', 'test.py')) os.execvp("python3", ("test.py", ))
How to call an executable as independent process using python in windows
0.197375
0
0
1,090
3,726,705
2010-09-16T12:38:00.000
0
0
0
0
python,django,pythonpath
3,726,747
2
false
1
0
As far as I know, it's just a matter of personal taste. I go with the directory which contains the project, but that's just my preference.
1
4
0
When developing a Django application, what is sys.path supposed to contain? The directory which contains the project, or the directory of the project, or both?
Django: What is `sys.path` supposed to be?
0
0
0
3,276
3,728,310
2010-09-16T15:42:00.000
0
0
1
1
python,netbeans
3,743,725
1
false
1
0
You probably want to ask this question on www.serverfault.com rather than stackoverflow as it is more of a configuration issue rather than a programming issue. Include the version of Netbeans and the Java you are using - and whether you using native python and/or Jython as well. Also include at which point you see the error message - when you create a new file, new project etc - does Netbeans start up ok etc ?
1
1
0
I have x64 Windows XP machine. I use Netbeans to code Java. I am now trying to use it for Python, but I get this error: \NetBeans was unexpected at this time. Any idea how to fix it?
Using Python in Netbeans
0
0
0
486
3,729,965
2010-09-16T19:17:00.000
1
1
0
1
python,scripting,path,bash
3,730,090
7
false
0
0
You shouldn't. It's the user choice whether he wants that in the PATH, in what cases and how to achieve that. What you can do is inform the user about the directory where your scripts reside and suggest putting it to the PATH. Or maybe you're asking from the user's perspective?
5
3
0
I am writing a python/pygtk application that is adding some custom scripts (bash) in a certain folder in $HOME (eg. ~/.custom_scripts). I want to make that folder available in $PATH. So every time the python app is adding the script, that script could be instantly available when the user is opening a terminal (eg. gnome-terminal). Where do you suggest to "inject" that $PATH dependecy ? .bashrc, /etc/profile.d, etc. ? What advantages / disadvantages I might encounter ? For example if i add a script to export the new path in /etc/profile.d, the path is not being updated until I re-login. Thanks
How to update $PATH
0.028564
0
0
3,792
3,729,965
2010-09-16T19:17:00.000
2
1
0
1
python,scripting,path,bash
3,730,011
7
false
0
0
.profile would be a reasonable place if it's a per-user install; /etc/profile.d for system-wide installs. (You'll need root to do that, of course.) Your installer won't be able to change the path of the current shell (unless it's being run via source, which would be...odd.)
5
3
0
I am writing a python/pygtk application that is adding some custom scripts (bash) in a certain folder in $HOME (eg. ~/.custom_scripts). I want to make that folder available in $PATH. So every time the python app is adding the script, that script could be instantly available when the user is opening a terminal (eg. gnome-terminal). Where do you suggest to "inject" that $PATH dependecy ? .bashrc, /etc/profile.d, etc. ? What advantages / disadvantages I might encounter ? For example if i add a script to export the new path in /etc/profile.d, the path is not being updated until I re-login. Thanks
How to update $PATH
0.057081
0
0
3,792
3,729,965
2010-09-16T19:17:00.000
2
1
0
1
python,scripting,path,bash
3,730,014
7
false
0
0
For scripts that go in the $HOME directory you'd typically use $HOME/bin folder instead which is (usually) on the path.
5
3
0
I am writing a python/pygtk application that is adding some custom scripts (bash) in a certain folder in $HOME (eg. ~/.custom_scripts). I want to make that folder available in $PATH. So every time the python app is adding the script, that script could be instantly available when the user is opening a terminal (eg. gnome-terminal). Where do you suggest to "inject" that $PATH dependecy ? .bashrc, /etc/profile.d, etc. ? What advantages / disadvantages I might encounter ? For example if i add a script to export the new path in /etc/profile.d, the path is not being updated until I re-login. Thanks
How to update $PATH
0.057081
0
0
3,792
3,729,965
2010-09-16T19:17:00.000
1
1
0
1
python,scripting,path,bash
3,730,027
7
true
0
0
~/.bashrc is read every time gnome-terminal is opened, (assuming the user has SHELL set to /bin/bash). Be sure to check os.environ['PATH'] to see if the directory has already been added, so that the script doesn't add it more than once.
5
3
0
I am writing a python/pygtk application that is adding some custom scripts (bash) in a certain folder in $HOME (eg. ~/.custom_scripts). I want to make that folder available in $PATH. So every time the python app is adding the script, that script could be instantly available when the user is opening a terminal (eg. gnome-terminal). Where do you suggest to "inject" that $PATH dependecy ? .bashrc, /etc/profile.d, etc. ? What advantages / disadvantages I might encounter ? For example if i add a script to export the new path in /etc/profile.d, the path is not being updated until I re-login. Thanks
How to update $PATH
1.2
0
0
3,792
3,729,965
2010-09-16T19:17:00.000
1
1
0
1
python,scripting,path,bash
3,730,001
7
false
0
0
/etc/profile.d would add it to every user's path ~/.bashrc would just be your own you can always do "$ source ~/.bashrc" to re-read the config files.
5
3
0
I am writing a python/pygtk application that is adding some custom scripts (bash) in a certain folder in $HOME (eg. ~/.custom_scripts). I want to make that folder available in $PATH. So every time the python app is adding the script, that script could be instantly available when the user is opening a terminal (eg. gnome-terminal). Where do you suggest to "inject" that $PATH dependecy ? .bashrc, /etc/profile.d, etc. ? What advantages / disadvantages I might encounter ? For example if i add a script to export the new path in /etc/profile.d, the path is not being updated until I re-login. Thanks
How to update $PATH
0.028564
0
0
3,792
3,731,681
2010-09-16T23:41:00.000
2
0
1
0
python,linux,input,interrupt
3,731,809
6
false
0
0
You need a separate process (or possibly a thread) to read the terminal and send it to the process of interest via some form of inter-process communication (IPC) (inter-thread communication may be harder -- basically the only thing you do is send a KeyboardInterrupt from a secondary thread to the main thread). Since you say "I was hoping there would be a simple way to inject user input into the loop other than just ^C", I'm sad to disappoint you, but that's the truth: there are ways to do what you request, but simple they aren't.
2
3
0
Is there a way to send an interrupt to a python module when the user inputs something in the console? For example, if I'm running an infinite while loop, i can surround it with a try/except for KeyboardInterrupt and then do what I need to do in the except block. Is there a way to duplicate this functionality with any arbitrary input? Either a control sequence or a standard character? Edit: Sorry, this is on linux
Capturing user input at arbitrary times in python
0.066568
0
0
2,997
3,731,681
2010-09-16T23:41:00.000
1
0
1
0
python,linux,input,interrupt
3,731,716
6
false
0
0
KeyboardInterrupt is special in that it can be trapped (i.e. SIGINT under operating systems with respective POSIX support, SetConsoleCtrlHandler on Windows) and handled accordingly. If you want to process user input while at the same time doing work in a otherwise blocking loop, have a look at the threading or subprocess modules, taking a look at how to exchange data between two different threads / processes. Also be sure to get an understanding of the issues that go hand in hand with parallel computing (i.e. race conditions, thread safety / synchronization etc.)
2
3
0
Is there a way to send an interrupt to a python module when the user inputs something in the console? For example, if I'm running an infinite while loop, i can surround it with a try/except for KeyboardInterrupt and then do what I need to do in the except block. Is there a way to duplicate this functionality with any arbitrary input? Either a control sequence or a standard character? Edit: Sorry, this is on linux
Capturing user input at arbitrary times in python
0.033321
0
0
2,997
3,732,595
2010-09-17T04:04:00.000
0
0
0
0
python,windows,search,hyperlink
3,732,721
2
false
0
0
Make sure that you change the User-Agent of urllib2. The default one tends to get blocked by Google. Make sure that you obey the terms of use of the search engine that you're scripting.
1
0
0
I am working on a project that requires me to collect a large list of URLs to websites about certain topics. I would like to write a script that will use google to search specific terms, then save the URLs from the results to a file. How would I go about doing this? I have used a module called xgoogle, but it always returned no results. I am using Python 2.6 on Windows 7.
Search Crawling "Bot"?
0
0
1
402
3,733,270
2010-09-17T07:00:00.000
2
0
1
1
python,timeout,pipe,subprocess,popen
3,733,359
10
false
0
0
Unfortunately, there isn't such a solution. I managed to do this using a threaded timer that would launch along with the process that would kill it after the timeout but I did run into some stale file descriptor issues because of zombie processes or some such.
1
19
0
Is there any argument or options to setup a timeout for Python's subprocess.Popen method? Something like this: subprocess.Popen(['..'], ..., timeout=20) ?
Python subprocess timeout?
0.039979
0
0
37,063
3,733,363
2010-09-17T07:20:00.000
0
0
0
1
python,networking,tcp
3,733,452
3
true
0
0
You often write clients in the plural form: are there several clients connecting to your server? In this case, each client should be using its own TCP stream, and the issue you are describing should never occur. If the various commands are send from a single client, then you should write your client code so that it waits for the answer to a command before issuing the next one.
2
0
0
I am going to write a TCP server, the client sends me XML message, I am wondering if below condition will happen and how to avoid that: 1) client sends <cmd ...></cmd> 2) sever is busy doing something 3) clients sends <cmd ...></cmd> 4) server does a recv() and put the string to buffer Will the buffer be filled with <cmd ...></cmd><cmd ...></cmd> or even worse <cmd ...></cmd><cmd ... if my buffer is not big enough? What I want is the TCP stack divides the messages to the same pieces as how clients sent them. Is it doable?
TCP server: how to avoid message overlapping
1.2
0
1
772
3,733,363
2010-09-17T07:20:00.000
4
0
0
1
python,networking,tcp
3,733,419
3
false
0
0
This is impossible to guarantee at the TCP level, since it only knows about streams. Depending on the XML parser you're using, you should be able to feed it the stream and have it tell you when it has a complete object, leaving the second <cmd... in its buffer until it is closed also.
2
0
0
I am going to write a TCP server, the client sends me XML message, I am wondering if below condition will happen and how to avoid that: 1) client sends <cmd ...></cmd> 2) sever is busy doing something 3) clients sends <cmd ...></cmd> 4) server does a recv() and put the string to buffer Will the buffer be filled with <cmd ...></cmd><cmd ...></cmd> or even worse <cmd ...></cmd><cmd ... if my buffer is not big enough? What I want is the TCP stack divides the messages to the same pieces as how clients sent them. Is it doable?
TCP server: how to avoid message overlapping
0.26052
0
1
772
3,735,183
2010-09-17T12:11:00.000
5
1
0
0
python,django,memcached,python-memcached
3,735,232
2
true
1
0
You should monitor your infrastructure. You can use a huge variety of tools for this, look on server fault for more discussions on monitoring. You should probably monitor your cache hit rate and trend it in your monitoring system; if it falls below a figure (say 90%) then you can alert that the cache has stopped working or something. Memcached itself will have some way of monitoring hit rate, but that will be overall rather than for a specific part of your application. You probably want to monitor the hit rate for a specific cache instance in your code so you can be sure it's continuing to be effective.
1
2
0
Is there some ready-made addon that alerts admins about memcached instance being inaccessible from a Django application? I don't mean here monitoring memcached daemon itself, but something that checks if my Django app benefits from caching. My basic idea is to check if cache.get that follow cache.set actually returns something, and if not - then send email to admins, but only one per hour, to not flood the inbox. But maybe there is something more advanced out there ?
Django - alert when memcached is down
1.2
0
0
481
3,736,311
2010-09-17T14:39:00.000
1
0
1
0
python,pychecker
4,782,453
3
false
0
0
On the bonus extra question: pychecker always imports the files you pass it, which causes it to import whatever those import. This is just like Python. This is a first pass in pychecker. Then pychecker will actually go through the loaded modules, disassemble the code, and run through all the opcodes. This is a second pass. In both cases, it tracks all warnings generated even by ignored modules. Then it filters out those warnings before showing them. I am considering if it is worth it to change pychecker to not even look at blacklisted modules at all, or make it possible to only disassemble the one file (for integration in an editor for example).
1
1
0
One of the modules I import into my python project triggers lots of warnings under Pychecker. Fixing up this external module isn't really an option, so I want to tell Pychecker to ignore it. Does anyone know how to do this? I'm sure it's possible, and probably quite simple, but after trawling Google for a while I've not found any documentation or examples. Thanks, Sam Edit: I can't tag this with 'pychecker' unfortunately as that tag doesn't exist yet and my rep is too low to create. Edit 2 Bonus extra question: does pychecker check ignored modules anyway, and just not print anything it finds? or do you get some speedup by ignoring some modules?
How can I tell Pychecker to ignore an imported library?
0.066568
0
0
1,754
3,736,497
2010-09-17T15:01:00.000
3
0
0
1
python,google-app-engine,cron
3,736,761
2
false
0
0
I would recommend just using every 5 minutes synchronized in the cron.yaml, and then just terminate immediately in the handler if the exact time is not to your liking (hour before 9 or after 20 and minute // 5 is odd, for example). GAE's cron is not very sophisticated, but running a trivial handler which just gets the time, checks whether that's OK, and terminates immediately otherwise, is pretty simple and cheap (and the 70 or so "extra hits per day", each with a trivial amount of resource consumption, will hardly make a difference to your app's overall resource consumption anyway).
1
0
0
How to config a cron job to run every 5 minutes between 9:00am~20:00pm, but every 10 minutes in other time of the day.
How to set Google App Engine cron job using different interval in different period of time?
0.291313
0
0
502
3,736,606
2010-09-17T15:15:00.000
4
1
0
0
python,http,cherrypy
3,737,124
2
true
0
0
CherryPy has a caching Tool, but it's never on by default. Most HTTP responses are cacheable by default, though, so look for an intermediate cache between your client and server. Look at the browser first. If you're not sure whether or not your content is being cached, compare the Date response header to the current time.
1
3
0
Is it possible that CherryPy, in its default configuration, is caching the responses to one or more of my request handlers? And, if so, how do I turn that off?
How to determine if CherryPy is caching responses?
1.2
0
1
2,007
3,737,922
2010-09-17T18:23:00.000
1
0
0
0
python
3,737,996
3
false
0
1
Are you running it from an iteractive prompt and want to just get back to the prompt. Or, are you running it from a shell and want to get to a python prompt in but with the current state of the programs execution? For the later it you could the keyboard interupt exception in your code and break out to the python debugger (pdb). import pdb try: mainProgramLoop() except (KeyboardInterrupt, SystemExit): pdb.set_trace()
1
4
0
I wrote a implementation of conway's game of life. I set up two modes, one is auto and the other is manual, which I mean the way to ouput the result of the game. For the auto mode, I cannot stop the running progran without ctrl + q or ctrl + c (which prints out the error message). So is there any way which can allow me to stop the running program and return to the python >>> prompt by pressing some key defined by myself, say, ctrl + k. Thank you.
How to quit the running python program to python prompt?
0.066568
0
0
3,663
3,739,296
2010-09-17T21:47:00.000
1
0
0
0
javascript,python,streaming,real-time
3,739,311
5
false
0
0
You could have the python script write an xml file that you get with an ajax request in your web page, and get the status info from that.
1
4
0
I have a simple workflow [Step 0]->[1]->[2]->...->[Step N]. The master program knows the step (state) it is currently at. I want to stream this in real time to a website (in the local area network) so that when my colleagues open, say, http://thecomputer:8000, they can see a real time rendering of the current state of our workflow with any relevant details. I've tought about writing the state of the script to an StringIO object (streaming to it) and use Javascript to refresh the browser, but I honestly have no idea how to actually do this. Any advice?
Streaming the state of a Python script to a website
0.039979
0
1
880
3,739,837
2010-09-18T00:05:00.000
0
0
1
1
python,cygwin,tcl
3,739,923
1
false
0
0
If you could change the variable, you know already which it is, and to which value it is set. Would you kindly share this information, maybe someone can make an educated guess?
1
0
0
Idle stopped working after installing cygwin and after some troubleshooting (on windows if its not obvious), it looks like the issue is with a TCL library. They both use an environment variable to locate tcl. when I installed cygwin, it overwrote the variable to a different (and incompatible to python) version. Now I figure I can just change the variable, but it seems kind of a hassle to switch between them all of the time. Does anyone have a good solution to this? (besides not using cygwin or something...)
is there a compatible TCL environment variable for cygwin and python idle
0
0
0
167
3,740,330
2010-09-18T04:02:00.000
2
0
0
0
python,architecture,frameworks,python-stackless
3,740,407
2
false
1
0
Before you can even begin to consider writing a continuation based framework you need a programming language that has continuations (or at least co-routines which can be used to emulate continuations). Continuation is a control structure like loops or closures or functions, not a design pattern like MVC. Unfortunately the (currently) standard Python does not support continuations. Which is one of the reason people developed stackless python. Java is a bit of a special case. The language itself does not support continuations but the virtual machine does (in order to support exceptions). I think what they did was to modify the compiled bytecode at runtime and re-order instructions so that it looks like it supports continuations. Kind of like implementing stackless python by monkey-patching.
2
0
0
There are many continuation based framework for java, ruby etc but none in python. Nagare framework somewhat solves the problem but it do not use standard python and uses stackless python to solve continuation problem. I was wondering, what part of standard python constraint to create such continuation web framework in standard python ? and What are the workaround to it ? and what are standard part in continuation framework architecture ( as model view controller are in MVC ) ?
design for continuation based python web appliction framework
0.197375
0
0
635
3,740,330
2010-09-18T04:02:00.000
2
0
0
0
python,architecture,frameworks,python-stackless
3,743,417
2
false
1
0
Right, continuation is a property of a language and CPython sadly has not continuations. The workarounds in pure Python are well known : use callbacks / deferers like Twisted and Tornado for example or use 'yield' everywhere to mimic co-routines, like Diesel. But both approaches force you to change the way you design and code your application. Also a continuation can be "replayed" which is how the continuation based frameworks automatically handle the "back" button problem. Finally, to be exact, in Nagare we are using the pickling of a freezed tasklet to obtain a continuation object.
2
0
0
There are many continuation based framework for java, ruby etc but none in python. Nagare framework somewhat solves the problem but it do not use standard python and uses stackless python to solve continuation problem. I was wondering, what part of standard python constraint to create such continuation web framework in standard python ? and What are the workaround to it ? and what are standard part in continuation framework architecture ( as model view controller are in MVC ) ?
design for continuation based python web appliction framework
0.197375
0
0
635
3,740,903
2010-09-18T08:29:00.000
2
0
0
0
python,dbus
13,629,355
2
false
0
0
this example does not work I think because : ''' The available properties and whether they are writable can be determined by calling org.freedesktop.DBus.Introspectable.Introspect, see the section called “org.freedesktop.DBus.Introspectable”. ''' and in introspection data the property are missing: I use dbus-python-1.1.1
1
6
0
In all python dbus documentations there are info on how to export objects, interfaces, signals, but there is nothing how to export interface property. Any ideas how to do that ?
Python Dbus : How to export Interface property
0.197375
0
0
5,868
3,740,932
2010-09-18T08:37:00.000
1
0
0
1
python,google-app-engine
3,740,943
1
true
1
0
Considering the distributed nature of GAE, I don't think you can do this directly. You can store visits in the database (with timestamp) and query this (use a cookie to check if a user is already counted, avoid writing on each request!). Alternatively, you can use some external service that uses included javascript or image that counts this for you, much like how analytics works.
1
0
0
Is there a way to count total number of active sessions (e.g. in 10 minutes) on Google App Engine (Python)? I want to show something on frontpage like, This site currently haz 200 people online
Total number of live sessions on GAE
1.2
0
0
94
3,740,960
2010-09-18T08:43:00.000
1
0
1
0
python,multithreading
3,740,986
1
false
0
0
You have two options, basically: threading and asynchronous IO. You can have one thread fill a Queue with entered data and have the other thread print its contents. Be warned that threading is hard (impossible?) to do right. Asynchronous IO means you have a main dispatcher that invokes callbacks when data is available (i.e. the user has entered data). There are frameworks that abstract most of this for you, such as asyncore and Twisted. Most GUI toolkits will also implement an asynchronous dispatching system through their mainloop, ie.. Tkinter, wxWidgets and pygtk. This will also solve the interface problems you have when mixing reading from and writing to the same (terminal) screen.
1
2
0
So I have a threaded Python program that takes input from a user and prints data simultaneously. The problem is that when the program is sitting at raw_input(), it won't print anything and will print it all after the user presses enter. Is there any way to have user input and print at the same time?
Raw input and printing simultaneously
0.197375
0
0
538
3,742,583
2010-09-18T16:55:00.000
1
0
1
1
python,windows-installer,metadata,md5
3,742,782
4
false
0
0
To answer your second question: no, there is no way to hash a PE file or ZIP file, ignoring the metadata, without locating and reading the metadata. This is because the metadata you're interested in is stored at variable locations in the file. In the case of PE files (EXE, DLL, etc), it's stored in a resource block, typically towards the end of the file, and a series of pointers and tables at the start of the file gives the location. In the case of ZIP files, it's scattered throughout the archive -- each included file is preceded by its own metadata, and then there's a table at the end giving the locations of each metadata block. But it sounds like you might actually be wanting to read the files within the ZIP archive and look for EXEs in there if you're after program metadata; the ZIP archive itself does not store company names or version numbers.
1
7
0
I am writing a Python script to index a large set of Windows installers into a DB. I would like top know how to read the metadata information (Company, Product Name, Version, etc) from EXE, MSI and ZIP files using Python running on Linux. Software I am using Python 2.6.5 on Ubuntu 10.04 64-bit with Django 1.2.1. Found so far: Windows command line utilities that can extract EXE metadata (like filever from SysUtils), or other individual CL utils that only work in Windows. I've tried running these through Wine but they have problems and it hasn't been worth the work to go and find the libs and frameworks that those CL utils depend on and try installing them in Wine/Crossover. Win32 modules for Python that can do some things but won't run in Linux (right?) Secondary question: Obviously changing the file's metadata would change the MD5 hashsum of the file. Is there a general method of hashing a file independent of the metadata besides locating it and reading it in (ex: like skipping the first 1024 byes?)
Read EXE, MSI, and ZIP file metadata in Python in Linux
0.049958
0
0
4,161
3,742,734
2010-09-18T17:36:00.000
6
0
0
0
python,django,django-models,django-urls,django-views
3,742,868
4
true
1
0
runserver.py restarts automatically every time you modify any .py file, but when you are using apache you have to restart the proccess manually.
3
7
0
In django framework,When there are changes in urls.py or model.py or views.py .We would restart httpd. But as the documentation says we could restart runserver to get the latest changes. Which is the best efficient way for doing the above
Django restart server or httpd
1.2
0
0
39,920
3,742,734
2010-09-18T17:36:00.000
4
0
0
0
python,django,django-models,django-urls,django-views
17,571,047
4
false
1
0
touch your_project_name.wsgi and save without any change. It will change data modify and django will automatically reloading code.
3
7
0
In django framework,When there are changes in urls.py or model.py or views.py .We would restart httpd. But as the documentation says we could restart runserver to get the latest changes. Which is the best efficient way for doing the above
Django restart server or httpd
0.197375
0
0
39,920
3,742,734
2010-09-18T17:36:00.000
1
0
0
0
python,django,django-models,django-urls,django-views
3,742,781
4
false
1
0
runserver refers to the development server that is distributed with Django. Restarting this one or your httpd are the same thing, in both cases you restart the webserver. If you're using apache, you are not using the development server that is startet by runserver.py.
3
7
0
In django framework,When there are changes in urls.py or model.py or views.py .We would restart httpd. But as the documentation says we could restart runserver to get the latest changes. Which is the best efficient way for doing the above
Django restart server or httpd
0.049958
0
0
39,920
3,743,222
2010-09-18T19:44:00.000
9
0
1
0
python,datetime
57,867,465
9
false
0
0
you could enter this code form for (today date & Names of the Day & hour) : datetime.datetime.now().strftime('%y-%m-%d %a %H:%M:%S') '19-09-09 Mon 17:37:56' and enter this code for (today date simply): datetime.date.today().strftime('%y-%m-%d') '19-09-10' for object : datetime.datetime.now().date() datetime.datetime.today().date() datetime.datetime.utcnow().date() datetime.datetime.today().time() datetime.datetime.utcnow().date() datetime.datetime.utcnow().time()
2
899
0
How do I convert a datetime.datetime object (e.g., the return value of datetime.datetime.now()) to a datetime.date object in Python?
How do I convert a datetime to date?
1
0
0
961,155