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
|
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
1,498,155 | 2009-09-30T13:32:00.000 | 1 | 1 | 0 | 1 | python,c,embedded,fuzzy-logic | 1,499,253 | 6 | false | 0 | 0 | If most of your runtime is spent in C libraries, the language you use to call these libraries isn't important. What language are your time-eating libraries written in ? | 6 | 5 | 0 | I'm looking at implementing a fuzzy logic controller based on either PyFuzzy (Python) or FFLL (C++) libraries.
I'd prefer to work with python but am unsure if the performance will be acceptable in the embedded environment it will work in (either ARM or embedded x86 proc both ~64Mbs of RAM).
The main concern is that response times are as fast as possible (an update rate of 5hz+ would be ideal >2Hz is required). The system would be reading from multiple (probably 5) sensors from an RS232 port and provide 2/3 outputs based on the results of the fuzzy evaluation.
Should I be concerned that Python will be too slow for this task? | Performance of Python worth the cost? | 0.033321 | 0 | 0 | 1,593 |
1,498,155 | 2009-09-30T13:32:00.000 | 0 | 1 | 0 | 1 | python,c,embedded,fuzzy-logic | 1,502,231 | 6 | false | 0 | 0 | From your description, speed should not be much of a concern (and you can use C, cython, whatever you want to make it faster), but memory would be. For environments with 64 Mb max (where the OS and all should fit as well, right ?), I think there is a good chance that python may not be the right tool for target deployment.
If you have non trivial logic to handle, I would still prototype in python, though. | 6 | 5 | 0 | I'm looking at implementing a fuzzy logic controller based on either PyFuzzy (Python) or FFLL (C++) libraries.
I'd prefer to work with python but am unsure if the performance will be acceptable in the embedded environment it will work in (either ARM or embedded x86 proc both ~64Mbs of RAM).
The main concern is that response times are as fast as possible (an update rate of 5hz+ would be ideal >2Hz is required). The system would be reading from multiple (probably 5) sensors from an RS232 port and provide 2/3 outputs based on the results of the fuzzy evaluation.
Should I be concerned that Python will be too slow for this task? | Performance of Python worth the cost? | 0 | 0 | 0 | 1,593 |
1,498,155 | 2009-09-30T13:32:00.000 | 0 | 1 | 0 | 1 | python,c,embedded,fuzzy-logic | 1,612,690 | 6 | false | 0 | 0 | I never really measured the performance of pyfuzzy's examples, but as the new version 0.1.0 can read FCL files as FFLL does. Just describe your fuzzy system in this format, write some wrappers, and check the performance of both variants.
For reading FCL with pyfuzzy you need the antlr python runtime, but after reading you should be able to pickle the read object, so you don't need the antlr overhead on the target. | 6 | 5 | 0 | I'm looking at implementing a fuzzy logic controller based on either PyFuzzy (Python) or FFLL (C++) libraries.
I'd prefer to work with python but am unsure if the performance will be acceptable in the embedded environment it will work in (either ARM or embedded x86 proc both ~64Mbs of RAM).
The main concern is that response times are as fast as possible (an update rate of 5hz+ would be ideal >2Hz is required). The system would be reading from multiple (probably 5) sensors from an RS232 port and provide 2/3 outputs based on the results of the fuzzy evaluation.
Should I be concerned that Python will be too slow for this task? | Performance of Python worth the cost? | 0 | 0 | 0 | 1,593 |
1,498,155 | 2009-09-30T13:32:00.000 | 35 | 1 | 0 | 1 | python,c,embedded,fuzzy-logic | 1,498,214 | 6 | true | 0 | 0 | In general, you shouldn't obsess over performance until you've actually seen it become a problem. Since we don't know the details of your app, we can't say how it'd perform if implemented in Python. And since you haven't implemented it yet, neither can you.
Implement the version you're most comfortable with, and can implement fastest, first. Then benchmark it. And if it is too slow, you have three options which should be done in order:
First, optimize your Python code
If that's not enough, write the most performance-critical functions in C/C++, and call that from your Python code
And finally, if you really need top performance, you might have to rewrite the whole thing in C++. But then at least you'll have a working prototype in Python, and you'll have a much clearer idea of how it should be implemented. You'll know what pitfalls to avoid, and you'll have an already correct implementation to test against and compare results to. | 6 | 5 | 0 | I'm looking at implementing a fuzzy logic controller based on either PyFuzzy (Python) or FFLL (C++) libraries.
I'd prefer to work with python but am unsure if the performance will be acceptable in the embedded environment it will work in (either ARM or embedded x86 proc both ~64Mbs of RAM).
The main concern is that response times are as fast as possible (an update rate of 5hz+ would be ideal >2Hz is required). The system would be reading from multiple (probably 5) sensors from an RS232 port and provide 2/3 outputs based on the results of the fuzzy evaluation.
Should I be concerned that Python will be too slow for this task? | Performance of Python worth the cost? | 1.2 | 0 | 0 | 1,593 |
1,498,155 | 2009-09-30T13:32:00.000 | 12 | 1 | 0 | 1 | python,c,embedded,fuzzy-logic | 1,498,176 | 6 | false | 0 | 0 | Python is very slow at handling large amounts of non-string data. For some operations, you may see that it is 1000 times slower than C/C++, so yes, you should investigate into this and do necessary benchmarks before you make time-critical algorithms in Python.
However, you can extend python with modules in C/C++ code, so that time-critical things are fast, while still being able to use python for the main code. | 6 | 5 | 0 | I'm looking at implementing a fuzzy logic controller based on either PyFuzzy (Python) or FFLL (C++) libraries.
I'd prefer to work with python but am unsure if the performance will be acceptable in the embedded environment it will work in (either ARM or embedded x86 proc both ~64Mbs of RAM).
The main concern is that response times are as fast as possible (an update rate of 5hz+ would be ideal >2Hz is required). The system would be reading from multiple (probably 5) sensors from an RS232 port and provide 2/3 outputs based on the results of the fuzzy evaluation.
Should I be concerned that Python will be too slow for this task? | Performance of Python worth the cost? | 1 | 0 | 0 | 1,593 |
1,499,268 | 2009-09-30T16:31:00.000 | -1 | 1 | 0 | 1 | python,linux | 1,499,282 | 3 | false | 0 | 0 | Use the command sudo.
In order to run a program as a user, the system must "authenticate" that user.
Obviously, root can run any program as any user, and any user can su to another user with a password.
The program sudo can be configured to allow a group of users to sudo a particular command as a particular user.
For example, you could create a group scriptUsers and a user scriptRun. Then, configure sudo to let any user in scriptUsers become scriptRun ONLY to run your script. | 2 | 14 | 0 | On a Linux box I want to run a Python script as another user.
I've already made a wrapper program in C++ that calls the script, since I've realized that the ownership of running the script is decided by the ownership of the python interpreter. After that I change the C++ program to a different user and run the C++ program.
This setup doesn't seem to be working. Any ideas? | Running python script as another user | -0.066568 | 0 | 0 | 33,209 |
1,499,268 | 2009-09-30T16:31:00.000 | 0 | 1 | 0 | 1 | python,linux | 1,499,313 | 3 | false | 0 | 0 | Give those users the ability to sudo su $dedicated_username and tailor the permissions on your system so that $dedicated_user has sufficient, but not excessive, access. | 2 | 14 | 0 | On a Linux box I want to run a Python script as another user.
I've already made a wrapper program in C++ that calls the script, since I've realized that the ownership of running the script is decided by the ownership of the python interpreter. After that I change the C++ program to a different user and run the C++ program.
This setup doesn't seem to be working. Any ideas? | Running python script as another user | 0 | 0 | 0 | 33,209 |
1,499,572 | 2009-09-30T17:32:00.000 | 1 | 0 | 0 | 1 | python,mysql,macos | 2,302,542 | 2 | false | 0 | 0 | You also need python_select (or is it select_python?) to change the default python used. | 1 | 0 | 0 | I just upgraded the default Python 2.5 on Leopard to 2.6 via the installer on www.python.org. Upon doing so, the MySQLdb I had installed was no longer found. So I tried reinstalling it via port install py-mysql, and it succeeded, but MySQLdb was still not importable. So then I tried to python install python26 with python_select python26 and it succeeded, but it doesn't appear that it is getting precedence over the python.org install:
$ which python
/Library/Frameworks/Python.framework/Versions/2.6/bin/python
When I would expect it to be something like /opt/local/bin/python
My path environment is: /Library/Frameworks/Python.framework/Versions/2.6/bin:/usr/local/mysql/bin/:/opt/local/bin:/opt/local/sbin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin:/usr/local/mysql/bin:/Users/bsr/bin
Anyway, when I try port install py-mysql but how does it know where to install the Python MySQL library? | With multiple Python installs, how does MacPorts know which one to install MySQLdb for? | 0.099668 | 1 | 0 | 1,051 |
1,500,564 | 2009-09-30T20:46:00.000 | 2 | 1 | 0 | 0 | python,scripting,numbers,profiler,line | 1,500,818 | 3 | false | 0 | 0 | cProfile does not track line numbers within a function; it only tracks the line number of where the function was defined.
cProfile attempts to duplicate the behavior of profile (which is pure Python). profile uses pstats to store the data from running, and pstats only stores line numbers for function definitions, not for individual Python statements.
If you need to figure out with finer granularity what is eating all your time, then you need to refactor your big function into several, smaller functions. | 1 | 5 | 0 | I'm using cProfile, pstats and Gprof2dot to profile a rather long python script.
The results tell me that the most time is spent calling a method in an object I've defined. However, what I would really like is to know exactly what line number within that function is eating up the time.
Any idea's how to get this additional information?
(By the way, I'm using Python 2.6 on OSX snow leopard if that helps...) | cProfile and Python: Finding the specific line number that code spends most time on | 0.132549 | 0 | 0 | 2,434 |
1,501,907 | 2009-10-01T04:36:00.000 | -1 | 0 | 0 | 1 | python,google-app-engine,cron | 1,501,925 | 4 | false | 1 | 0 | Looking over the docs, I agree that your 24 cron entry idea is the only documented way that would work. Not ideal, but should work. | 2 | 4 | 0 | I need to run a task every hour on the hour (00:00, 01:00, 02:00, ..., 23:00) every day of the week, but can't seem to find an example in App Engine's docs of how to do this.
There is an example of running at ask every hour, but this doesn't fit because the "start" of that hour depends on when you deploy the application. That is, if I deploy at 4:37 PM, the cron scripts will get executed at 5:37, 6:37, ... instead of 5:00, 6:00, ...
So far the only way that looks like it would work is to have 24 different cron entries, one for the specific hour of each day set to run each day at that specific time.
Does anyone know of anything that would let me use a schedule like "every hour at :00" or even "every day 00:00, 01:00, ... 23:00"? | Run a task every hour on the hour with App Engine's cron API | -0.049958 | 0 | 0 | 3,297 |
1,501,907 | 2009-10-01T04:36:00.000 | 1 | 0 | 0 | 1 | python,google-app-engine,cron | 1,501,960 | 4 | false | 1 | 0 | The docs say you can have 20 cron entries, so you can't have one for every hour of the day.
You could run your task every minute and check if it is the first minute of the hour - exit otherwise. | 2 | 4 | 0 | I need to run a task every hour on the hour (00:00, 01:00, 02:00, ..., 23:00) every day of the week, but can't seem to find an example in App Engine's docs of how to do this.
There is an example of running at ask every hour, but this doesn't fit because the "start" of that hour depends on when you deploy the application. That is, if I deploy at 4:37 PM, the cron scripts will get executed at 5:37, 6:37, ... instead of 5:00, 6:00, ...
So far the only way that looks like it would work is to have 24 different cron entries, one for the specific hour of each day set to run each day at that specific time.
Does anyone know of anything that would let me use a schedule like "every hour at :00" or even "every day 00:00, 01:00, ... 23:00"? | Run a task every hour on the hour with App Engine's cron API | 0.049958 | 0 | 0 | 3,297 |
1,502,431 | 2009-10-01T07:37:00.000 | 3 | 0 | 1 | 1 | python,debugging,cherrypy | 1,502,612 | 1 | false | 0 | 0 | No. Not only does the wsgiserver start its own set of worker threads (10 by default, but even if you only specified 1 that's still 1 thread for the listening socket and 1 worker thread). Even if that were not true, if you use the rest of CherryPy (i.e. the engine), it runs that 1 listener thread in a separate thread from the main thread. | 1 | 1 | 0 | Is it possible to use the CherrPy server as a blocking/non-threading server (for easier debugging?) | Using CherryPy as a blocking/non-threading server for easier debugging | 0.53705 | 0 | 0 | 934 |
1,504,804 | 2009-10-01T15:55:00.000 | 5 | 1 | 1 | 0 | c#,.net,ironpython | 1,551,802 | 4 | false | 1 | 0 | If I wanted to just "learn the framework", I would do it in C# or VB for two main reasons:
Intellisense - the framework is huge, and being offered suggestions for function overloads is one of the ways to find new stuff. There's almost no good intellisense for the framework with IronPython at the moment (Michael Foord has done some work on building the appropriate info for Wing, but I haven't tried it myself).
Code samples - pretty much all the educational material that exists about the .NET framework is given with C# or VB. You'll be much more on your own with IronPython. | 3 | 4 | 0 | Because I'm a Python fan, I'd like to learn the .NET framework using IronPython. Would I be missing out on something? Is this in some way not recommended?
EDIT:
I'm pretty knowledgeable of Java ( so learning/using a new language is not a problem for me ). If needed, will I be able to use everything I learned in IronPython ( excluding language featurs ) to write C# code? | Using IronPython to learn the .NET framework, is this bad? | 0.244919 | 0 | 0 | 477 |
1,504,804 | 2009-10-01T15:55:00.000 | 11 | 1 | 1 | 0 | c#,.net,ironpython | 1,504,823 | 4 | true | 1 | 0 | No, sounds like a good way to learn to me. You get to stick with a language and syntax that you are familiar with, and learn about the huge range of classes available in the framework, and how the CLR supports your code.
Once you've got to grips with some of the framework and the CLR services you could always pick up C# in the future. By that point it will just be a minor syntax change from what you already know.
Bare in mind that if you are thinking with respect to a career, you won't find many iron python jobs, but like I say, this could be a good way to learn about the framework first, then build on that with C# in a month or twos time. | 3 | 4 | 0 | Because I'm a Python fan, I'd like to learn the .NET framework using IronPython. Would I be missing out on something? Is this in some way not recommended?
EDIT:
I'm pretty knowledgeable of Java ( so learning/using a new language is not a problem for me ). If needed, will I be able to use everything I learned in IronPython ( excluding language featurs ) to write C# code? | Using IronPython to learn the .NET framework, is this bad? | 1.2 | 0 | 0 | 477 |
1,504,804 | 2009-10-01T15:55:00.000 | 5 | 1 | 1 | 0 | c#,.net,ironpython | 1,504,904 | 4 | false | 1 | 0 | You can definitely do that to learn the class library, but I'm not sure if it's such a good idea when it comes to fundamental CLR concepts (e.g. delegates and events). You'll need to pay attention and distinguish what is strictly an IronPython feature, and what is CLR feature exposed in IronPython in a way that matches its dynamic semantics better. | 3 | 4 | 0 | Because I'm a Python fan, I'd like to learn the .NET framework using IronPython. Would I be missing out on something? Is this in some way not recommended?
EDIT:
I'm pretty knowledgeable of Java ( so learning/using a new language is not a problem for me ). If needed, will I be able to use everything I learned in IronPython ( excluding language featurs ) to write C# code? | Using IronPython to learn the .NET framework, is this bad? | 0.244919 | 0 | 0 | 477 |
1,505,744 | 2009-10-01T18:45:00.000 | 0 | 0 | 0 | 1 | python,networking,network-programming,twisted | 1,506,213 | 3 | false | 1 | 0 | Why not use a database instead of "just a structure"? Both relational and non-relational DBs offer many practical advantages (separate processes using them, take care of replication [[and/or snapshots, backups, ...]], rich functionality if you need it for the "queries", and so on, and so forth).
Worst case, the "just a structure" can be handled by a third process that's entirely dedicated to it (basically mimicking what any DB engine would offer -- though the engine would probably do it better and faster;-), allowing you to at least keep a good decomposition (with the two server processes both interacting with the "datastore process"). | 1 | 0 | 0 | I have a problem as follows:
Server process 1
Constantly sends updates that occur to a datastore
Server process 2
Clients contact the server, which queries the datastore, and returns a result
The thing is, the results that process 1 and process 2 are sending back the client are totally different and unrelated.
How does one decompose this?
Do you just have one process constantly sending data, and define the protocol to have a bit which corresponds to whether the return type is 1 or 2?
Do you have two processes? How do they share the datastore then (it is just a structure not a database)?
Thanks! | Network programming abstraction, decomposition | 0 | 0 | 0 | 290 |
1,506,647 | 2009-10-01T21:37:00.000 | 3 | 0 | 0 | 0 | python,matplotlib,boxplot | 1,506,741 | 3 | false | 0 | 0 | Try axis('equal'). It's been a while since I worked with matplotlib, but I seem to remember typing that command a lot. | 1 | 4 | 1 | I have a plot of two boxplots in the same figure. For style reasons, the axis should have the same length, so that the graphic box is square. I tried to use the set_aspect method, but the axes are too different because of their range
and the result is terrible.
Is it possible to have 1:1 axes even if they do not have the same number of points? | Matplotlib square boxplot | 0.197375 | 0 | 0 | 8,361 |
1,506,901 | 2009-10-01T22:45:00.000 | 314 | 1 | 1 | 0 | python,datetime,date,time | 1,506,916 | 7 | true | 0 | 0 | datetime.date.today() + datetime.timedelta(days=1) should do the trick | 1 | 166 | 0 | What is the cleanest and most Pythonic way to get tomorrow's date? There must be a better way than to add one to the day, handle days at the end of the month, etc. | Cleanest and most Pythonic way to get tomorrow's date? | 1.2 | 0 | 0 | 110,489 |
1,507,041 | 2009-10-01T23:32:00.000 | 10 | 0 | 1 | 0 | python | 1,507,054 | 8 | false | 0 | 0 | Read other people's code. Write some of your own code. Repeat for a year or two.
Study the Python documentation and learn the built-in modules.
Read Python in a Nutshell.
Subscribe your RSS reader to the Python tag on Stack Overflow. | 3 | 10 | 0 | Once you have learned the basic commands in Python, you are often able to solve most programming problem you face. But the way in which this is done is not really Python-ic.
What is common is to use the classical c++ or Java mentality to solve problems. But Python is more than that. It has functional programming incorporated; many libraries available; object oriented, and its own ways. In short there are often better, shorter, faster, more elegant ways to the same thing.
It is a little bit like learning a new language. First you learn the words and the grammar, but then you need to get fluent.
Once you have learned the language, how do you get fluent in Python? How have you done it? What books mostly helped? | How do I get fluent in Python? | 1 | 0 | 0 | 14,330 |
1,507,041 | 2009-10-01T23:32:00.000 | 2 | 0 | 1 | 0 | python | 1,507,058 | 8 | false | 0 | 0 | I guess becoming fluent in any programming language is the same as becoming fluent in a spoken/written language. You do that by speaking and listening to the language, a lot.
So my advice is to do some projects using python, and you will soon become fluent in it. You can complement this by reading other people's code who are more experienced in the language to see how they solve certain problems. | 3 | 10 | 0 | Once you have learned the basic commands in Python, you are often able to solve most programming problem you face. But the way in which this is done is not really Python-ic.
What is common is to use the classical c++ or Java mentality to solve problems. But Python is more than that. It has functional programming incorporated; many libraries available; object oriented, and its own ways. In short there are often better, shorter, faster, more elegant ways to the same thing.
It is a little bit like learning a new language. First you learn the words and the grammar, but then you need to get fluent.
Once you have learned the language, how do you get fluent in Python? How have you done it? What books mostly helped? | How do I get fluent in Python? | 0.049958 | 0 | 0 | 14,330 |
1,507,041 | 2009-10-01T23:32:00.000 | 3 | 0 | 1 | 0 | python | 1,507,068 | 8 | false | 0 | 0 | The same way you get fluent in any language - program a lot.
I'd recommend working on a project (hopefully something you'll actually use later). While working on the project, every time you need some basic piece of functionality, try writing it yourself, and then checking online how other people did it.
This both lets you learn how to actually get stuff done in Python, but will also allow you to see what are the "Pythonic" counterparts to common coding cases. | 3 | 10 | 0 | Once you have learned the basic commands in Python, you are often able to solve most programming problem you face. But the way in which this is done is not really Python-ic.
What is common is to use the classical c++ or Java mentality to solve problems. But Python is more than that. It has functional programming incorporated; many libraries available; object oriented, and its own ways. In short there are often better, shorter, faster, more elegant ways to the same thing.
It is a little bit like learning a new language. First you learn the words and the grammar, but then you need to get fluent.
Once you have learned the language, how do you get fluent in Python? How have you done it? What books mostly helped? | How do I get fluent in Python? | 0.07486 | 0 | 0 | 14,330 |
1,507,075 | 2009-10-01T23:44:00.000 | 0 | 0 | 0 | 0 | python,file-io,wxpython,wxwidgets,mmap | 1,507,087 | 2 | false | 0 | 1 | Are people really going to read (or need) all 10MB in a text control? Probably not.
Suggest that, you load on demand by paging in portions of the data.
Or better still, provide some user search functionality that narrows down the results to the information of interest. | 1 | 0 | 0 | I am trying to display search result data quickly. I have all absolute file paths for files on my network drive(s) in a single, ~50MB text file. The python script makes a single pass over every line in this file [kept on the local drive] in a second or less, and that is acceptable. That is the time it takes to gather results.
However, the results are given in a wx.TextCtrl widget. Appending them line by line to a wx TextCtrl would be ridiculous. The best method I have come up with is to write the results to a text file, and call wx.TextCtrl's LoadFile native, which, depending on the number of results, loads the lines of text into the pane in between 0.1 to 5 seconds or so. However there must be a faster way for 10+MB of text inbound. The results are immediately calculated and available in the same process as the GUI... so please, tell me is there any way I can pipe/proxy/hack that data directly into the TextCtrl? Would mmap help this transfer? | wx.TextCtrl.LoadFile() | 0 | 0 | 0 | 1,831 |
1,507,082 | 2009-10-01T23:47:00.000 | 2 | 0 | 1 | 0 | python,exception | 1,507,245 | 7 | false | 0 | 0 | I concur with all of the above.
There's really no other way to signal that something went wrong in the initialisation of an object other than raising an exception.
In most programs classes where the state of a class is wholly dependant on the inputs to that class we might expect some kind of ValueError or TypeError to be raised.
Classes with side-effects (e.g. one which does networking or graphics) might raise an error in init if (for example) the network device is unavailable or the canvas object cannot be written to. This sounds sensible to me because often you want to know about failure conditions as soon as possible. | 5 | 153 | 0 | Is it considered bad form to raise exceptions within __init__? If so, then what is the accepted method of throwing an error when certain class variables are initialized as None or of an incorrect type? | Python: Is it bad form to raise exceptions within __init__? | 0.057081 | 0 | 0 | 65,275 |
1,507,082 | 2009-10-01T23:47:00.000 | 3 | 0 | 1 | 0 | python,exception | 1,507,112 | 7 | false | 0 | 0 | I should think it is the perfect case for the built-in ValueError exception. | 5 | 153 | 0 | Is it considered bad form to raise exceptions within __init__? If so, then what is the accepted method of throwing an error when certain class variables are initialized as None or of an incorrect type? | Python: Is it bad form to raise exceptions within __init__? | 0.085505 | 0 | 0 | 65,275 |
1,507,082 | 2009-10-01T23:47:00.000 | 2 | 0 | 1 | 0 | python,exception | 18,825,585 | 7 | false | 0 | 0 | Raising errors from init is unavoidable in some cases, but doing too much work in init is a bad style. You should consider making a factory or a pseudo-factory - a simple classmethod that returns setted up object. | 5 | 153 | 0 | Is it considered bad form to raise exceptions within __init__? If so, then what is the accepted method of throwing an error when certain class variables are initialized as None or of an incorrect type? | Python: Is it bad form to raise exceptions within __init__? | 0.057081 | 0 | 0 | 65,275 |
1,507,082 | 2009-10-01T23:47:00.000 | 187 | 0 | 1 | 0 | python,exception | 1,507,127 | 7 | true | 0 | 0 | Raising exceptions within __init__() is absolutely fine. There's no other good way to indicate an error condition within an initializer, and there are many hundreds of examples in the standard library where initializing an object can raise an exception.
The error class to raise, of course, is up to you. ValueError is best if the initializer was passed an invalid parameter. | 5 | 153 | 0 | Is it considered bad form to raise exceptions within __init__? If so, then what is the accepted method of throwing an error when certain class variables are initialized as None or of an incorrect type? | Python: Is it bad form to raise exceptions within __init__? | 1.2 | 0 | 0 | 65,275 |
1,507,082 | 2009-10-01T23:47:00.000 | 11 | 0 | 1 | 0 | python,exception | 1,507,130 | 7 | false | 0 | 0 | I don't see any reason that it should be bad form.
On the contrary, one of the things exceptions are known for doing well, as opposed to returning error codes, is that error codes usually can't be returned by constructors. So at least in languages like C++, raising exceptions is the only way to signal errors. | 5 | 153 | 0 | Is it considered bad form to raise exceptions within __init__? If so, then what is the accepted method of throwing an error when certain class variables are initialized as None or of an incorrect type? | Python: Is it bad form to raise exceptions within __init__? | 1 | 0 | 0 | 65,275 |
1,508,256 | 2009-10-02T08:09:00.000 | 7 | 1 | 1 | 0 | python,comparison,language-features,smalltalk,language-comparisons | 1,508,312 | 5 | false | 0 | 0 | Python certainly does have metaclasses.
Smalltalk has some unusual features:
Has a rather simple syntax and only about 6 (!) keywords. Everything else (including defining new classes) is accomplished by calling methods (sending messages in Smalltalk). This allows you to create some DSL within the language.
In Smalltalk, you don't store source files, but instead have one big memory image and you modify it on the fly. You can also modify most of the Smalltalk itself (and possibly break it ;) | 1 | 7 | 0 | I've seen some comparisons between Smalltalk and Ruby on the one hand and Ruby and Python on the other, but not between Python and Smalltalk. I'd especially like to know what the fundamental differences in Implementation, Syntax, Extensiabillity and Philosophy are.
For example Python does not seem to have Metaclasses. Smalltalk has no concept of generators. And although both are said to be dynamicly typed, I believe that Python does not do dynamic method dispatch. Is this correct? | How does Smalltalk (Pharo for example) compare to Python? | 1 | 0 | 0 | 3,672 |
1,508,906 | 2009-10-02T11:03:00.000 | 5 | 0 | 1 | 0 | python | 1,508,919 | 8 | false | 0 | 0 | You really want to stick with the later version. Python 2.6 and the rest of the 2.x versions that come out are really for compatibility. However, this is not true if you want to use a framework like Django right away because it is incompatible with the 3.x series at the moment.
A tip for learning Python? Just start using it and find online documentation for it. I feel it's an easy (and awesome) language to pick up. | 4 | 6 | 0 | I am about to learn Python and was wondering what is recommended, learning python 2.6 or 3.1? (any tips on learning python is welcomed as well =)
edit: Is the difference really big between the two? If I learn python 2 will i have trouble learning python 3? | python 2.6 or python 3.1? | 0.124353 | 0 | 0 | 2,505 |
1,508,906 | 2009-10-02T11:03:00.000 | -1 | 0 | 1 | 0 | python | 1,508,931 | 8 | false | 0 | 0 | If you want to use existing libraries and modules written in C/C++ or use SWIG, you'll have to use python2, otherwise I don't really see a reason to stick with python2. | 4 | 6 | 0 | I am about to learn Python and was wondering what is recommended, learning python 2.6 or 3.1? (any tips on learning python is welcomed as well =)
edit: Is the difference really big between the two? If I learn python 2 will i have trouble learning python 3? | python 2.6 or python 3.1? | -0.024995 | 0 | 0 | 2,505 |
1,508,906 | 2009-10-02T11:03:00.000 | 10 | 0 | 1 | 0 | python | 1,508,929 | 8 | false | 0 | 0 | I would go with 2.6 for a couple of reasons.
There's so much more material (books, examples, etc) based on 2.6. Some things might not work under 3.x, and you'll be able to get some good second-hand deals on 2.4-6 books.
The majority of libraries you'll want to pull in are still aimed at 2.6. This will change in time, but 2.6 support won't vanish overnight. Far from it. Linux distributions (that have a lot tied into python) aren't planning to move on for at least another year, so you're safe! | 4 | 6 | 0 | I am about to learn Python and was wondering what is recommended, learning python 2.6 or 3.1? (any tips on learning python is welcomed as well =)
edit: Is the difference really big between the two? If I learn python 2 will i have trouble learning python 3? | python 2.6 or python 3.1? | 1 | 0 | 0 | 2,505 |
1,508,906 | 2009-10-02T11:03:00.000 | 5 | 0 | 1 | 0 | python | 1,509,308 | 8 | false | 0 | 0 | You would want to go with 2.6 today.
Why? Because there is no library support for 3.1. We've just finished porting setuptools (under the name Distribute) to Python 3, so hopefully library support for Python 3 will increase dramatically during the next year, but it's not there yet.
And it's not so hard to switch. It's not like it's a whole new language, like some Python critics make it sound like. So if you start with Python 3, it's no disaster either. It's just that it's going to be hard to actually be productive in Python 3 at the moment. So go with 2.6. | 4 | 6 | 0 | I am about to learn Python and was wondering what is recommended, learning python 2.6 or 3.1? (any tips on learning python is welcomed as well =)
edit: Is the difference really big between the two? If I learn python 2 will i have trouble learning python 3? | python 2.6 or python 3.1? | 0.124353 | 0 | 0 | 2,505 |
1,509,404 | 2009-10-02T13:10:00.000 | 1 | 0 | 0 | 0 | python,mechanize | 1,509,434 | 1 | true | 0 | 0 | By parsing the browser contents with lxml, which has xpath support. | 1 | 0 | 0 | I've got a form, returned by Python mechanize Browser and got via forms() method. How can I perform XPath search inside form node, that is, among descendant nodes of the HTML form node? TIA
Upd:
How to save html code of the form? | How to search XPath inside Python ClientForm object? | 1.2 | 0 | 1 | 596 |
1,510,018 | 2009-10-02T14:52:00.000 | -1 | 0 | 1 | 0 | python,sqlalchemy,constraints | 1,510,137 | 2 | false | 0 | 0 | I'm pretty sure that unique constraints can only be applied on columns that already have data in them, and not on runtime-calculated expressions. Hence, you would need to create an extra column which contains the year part of your date, over which you could create a unique constraint together with number. To best use this approach, maybe you should store your date split up in three separate columns containing the day, month and year part. This could be done using default constraints in the table definition. | 1 | 3 | 0 | A quick SQLAlchemy question...
I have a class "Document" with attributes "Number" and "Date". I need to ensure that there's no duplicated number for the same year, is
there a way to have a UniqueConstraint on "Number + year(Date)"? Should I use a unique Index instead? How would I declare the functional part?
(SQLAlchemy 0.5.5, PostgreSQL 8.3.4)
Thanks in advance! | Compound UniqueConstraint with a function | -0.099668 | 1 | 0 | 890 |
1,510,084 | 2009-10-02T15:01:00.000 | 1 | 0 | 0 | 0 | python,ruby-on-rails,frameworks,python-3.x | 1,510,491 | 5 | false | 0 | 0 | Python 3 isn't ready for web applications right now. The WSGI 1.0 specification isn't suitable for Py3k and the related standard libraries are 2to3 hacks that don't work consistently faced with bytes vs. unicode. It's a real mess.
WEB-SIG are bashing out proposals for a WSGI revision; hopefully it can move forward soon, because although Python 3 isn't mainstream yet it's certainly heading that way, and the brokenness of webdev is rather embarrassing. | 3 | 1 | 0 | One of the feature I like in RoR is the db management, it can hide all the sql statement, also, it is very easy to change different db in RoR, is there any similar framework in Python 3000? | Is there any framework like RoR on Python 3000? | 0.039979 | 1 | 0 | 614 |
1,510,084 | 2009-10-02T15:01:00.000 | 0 | 0 | 0 | 0 | python,ruby-on-rails,frameworks,python-3.x | 1,510,218 | 5 | false | 0 | 0 | Python 3 is not ready for practical use, because there is not yet enough libraries that have been updated to support Python 3. So the answer is: No.
But there are LOADS of them on Python 2. Tens, at least.
Django, Turbogears, BFG and of course the old man of the game: Zope. To tell which is best for you, you need to expand your requirements a lot. | 3 | 1 | 0 | One of the feature I like in RoR is the db management, it can hide all the sql statement, also, it is very easy to change different db in RoR, is there any similar framework in Python 3000? | Is there any framework like RoR on Python 3000? | 0 | 1 | 0 | 614 |
1,510,084 | 2009-10-02T15:01:00.000 | 2 | 0 | 0 | 0 | python,ruby-on-rails,frameworks,python-3.x | 1,512,245 | 5 | false | 0 | 0 | I believe CherryPy is on the verge of being released for Python 3.X. | 3 | 1 | 0 | One of the feature I like in RoR is the db management, it can hide all the sql statement, also, it is very easy to change different db in RoR, is there any similar framework in Python 3000? | Is there any framework like RoR on Python 3000? | 0.07983 | 1 | 0 | 614 |
1,510,188 | 2009-10-02T15:17:00.000 | 0 | 1 | 1 | 0 | python,utf-8,codec,seek | 1,510,303 | 4 | false | 0 | 0 | Update: You can't do seek/tell on the object returned by codec.open(). You need to use a normal file, and decode the strings to unicode after reading.
I do not know why it doesn't work but I can't make it work. The seek seems to only work once, for example. Then you need to close and reopen the file, which is of course not useful.
The tell does not use character positions, but doesn't show you where your position in the stream is (but probably where the underlying file object is in reading from disk).
So probably because of some sort of underlying buffering, you can't do it. But deocding after reading works just fine, so go for that. | 3 | 6 | 0 | I have an application that generates some large log files > 500MB.
I have written some utilities in Python that allows me to quickly browse the log file and find data of interest. But I now get some datasets where the file is too big to load it all into memory.
I thus want to scan the document once, build an index and then only load the section of the document into memory that I want to look at at a time.
This works for me when I open a 'file' read it one line at a time and store the offset with from file.tell().
I can then come back to that section of the file later with file.seek( offset, 0 ).
My problem is however that I may have UTF-8 in the log files so I need to open them with the codecs module (codecs.open(<filename>, 'r', 'utf-8')). With the resulting object I can call seek and tell but they do not match up.
I assume that codecs needs to do some buffering or maybe it returns character counts instead of bytes from tell?
Is there a way around this? | Can seek and tell work with UTF-8 encoded documents in Python? | 0 | 0 | 0 | 2,140 |
1,510,188 | 2009-10-02T15:17:00.000 | 3 | 1 | 1 | 0 | python,utf-8,codec,seek | 1,510,276 | 4 | true | 0 | 0 | If true, this sounds like a bug or limitation of the codecs module, as it's probably confusing byte and character offsets.
I would use the regular open() function for opening the file, then seek()/tell() will give you byte offsets that are always consistent. Whenever you want to read, use f.readline().decode('utf-8').
Beware though, that using the f.read() function can land you in the middle of a multi-byte character, thus producing an UTF-8 decode error. readline() will always work.
This doesn't transparently handle the byte-order mark for you, but chances are your log files do not have BOMs anyway. | 3 | 6 | 0 | I have an application that generates some large log files > 500MB.
I have written some utilities in Python that allows me to quickly browse the log file and find data of interest. But I now get some datasets where the file is too big to load it all into memory.
I thus want to scan the document once, build an index and then only load the section of the document into memory that I want to look at at a time.
This works for me when I open a 'file' read it one line at a time and store the offset with from file.tell().
I can then come back to that section of the file later with file.seek( offset, 0 ).
My problem is however that I may have UTF-8 in the log files so I need to open them with the codecs module (codecs.open(<filename>, 'r', 'utf-8')). With the resulting object I can call seek and tell but they do not match up.
I assume that codecs needs to do some buffering or maybe it returns character counts instead of bytes from tell?
Is there a way around this? | Can seek and tell work with UTF-8 encoded documents in Python? | 1.2 | 0 | 0 | 2,140 |
1,510,188 | 2009-10-02T15:17:00.000 | 2 | 1 | 1 | 0 | python,utf-8,codec,seek | 1,510,282 | 4 | false | 0 | 0 | For UTF-8, you don't actually need to open the file with codecs.open. Instead, it is reliable to read the file as a byte string first, and only then decode an individual section (invoking the .decode method on the string). Breaking the file at line boundaries is safe; the only unsafe way to split it would be in the middle of a multi-byte character (which you can recognize from its byte value > 128). | 3 | 6 | 0 | I have an application that generates some large log files > 500MB.
I have written some utilities in Python that allows me to quickly browse the log file and find data of interest. But I now get some datasets where the file is too big to load it all into memory.
I thus want to scan the document once, build an index and then only load the section of the document into memory that I want to look at at a time.
This works for me when I open a 'file' read it one line at a time and store the offset with from file.tell().
I can then come back to that section of the file later with file.seek( offset, 0 ).
My problem is however that I may have UTF-8 in the log files so I need to open them with the codecs module (codecs.open(<filename>, 'r', 'utf-8')). With the resulting object I can call seek and tell but they do not match up.
I assume that codecs needs to do some buffering or maybe it returns character counts instead of bytes from tell?
Is there a way around this? | Can seek and tell work with UTF-8 encoded documents in Python? | 0.099668 | 0 | 0 | 2,140 |
1,511,808 | 2009-10-02T21:13:00.000 | 3 | 0 | 1 | 0 | python,file,distribution,py2exe,distutils | 1,511,907 | 2 | true | 0 | 0 | I just used shutil.copytree, which takes an ignore kwd arg. | 1 | 2 | 0 | I want to copy a data directory into my distribution dir. copy_tree does this just fine. However, the project is also an svn repository, and I don't want the distribution to have all the .svn files that the data dir has. Is there any easy way to do a copy_tree excluding the .svn files, or should I just write my own recursive dir copy? I feel someone must have had this issue before. | Python distutils - copy_tree with filter | 1.2 | 0 | 0 | 2,747 |
1,511,854 | 2009-10-02T21:22:00.000 | 4 | 1 | 1 | 0 | python,module,cron | 3,256,325 | 3 | false | 0 | 0 | I could be wrong but doesn't python crontab offer ways to read and write to crontab but nothing regarding parsing the crontab to determine the time until the next time a job will be run? | 1 | 4 | 0 | All. I am trying to find a python module that I can use to parse a cron entry and get the next time it will run. With perl I use the Schedule::Cron::Events module but I would like to convert to python. Thanks in advance. | Parse a cron entry in Python | 0.26052 | 0 | 0 | 8,165 |
1,512,389 | 2009-10-03T00:21:00.000 | 3 | 0 | 0 | 0 | python,google-app-engine,web-applications | 1,512,414 | 2 | true | 1 | 0 | You'd have to wrap the instance of WSGIApplication with your own WSGI app that lowercases the URL in the WSGI environment -- but then the environment would just stay modified, which may have other unpleasant effects. Why not just add (?i) to the regex patterns you use in urlpatterns instead? | 1 | 0 | 0 | Is there any straightforward to convert all incoming urls to lowercase before they get matched against urlpatterns in run_wsgi_app(webapp.WSGIApplication(urlpatterns))? | Converting urls into lowercase? | 1.2 | 0 | 0 | 344 |
1,512,530 | 2009-10-03T01:33:00.000 | 3 | 0 | 1 | 1 | python,macos,port,osx-leopard,lxml | 1,513,810 | 2 | false | 0 | 0 | Ned :
incompatible changes in the 2.6.3 version of python's distutil
Not precisely. The API hasn't changed but Setuptools overrides them, and makes the assumption they are called in a particular order.
Lennart:
The Distribute installation doesn't seem to trigger the bug
Yes indeed, this precise bug was detected some time ago and fixed in Distribute (and in Ubuntu's setuptools package) | 1 | 4 | 0 | I try to:
easy_install lxml
and I get this error:
File "build/bdist.macosx-10.3-fat/egg/setuptools/command/build_ext.py", line 85, in get_ext_filename
KeyError: 'etree'
any hints? | can't install lxml (python 2.6.3, osx 10.6 snow leopard) | 0.291313 | 0 | 0 | 2,271 |
1,512,644 | 2009-10-03T02:45:00.000 | 1 | 1 | 1 | 0 | python,release-management,pypi | 1,513,884 | 2 | true | 0 | 0 | You don't need to release eggs for anything else than Windows, and then only if your package uses C extensions so that they have compiled parts. Otherwise you simply release one source distribution. That will be enough for all Python versions on all platforms.
Running the tests for different versions automated is tricky if you don't have a buildbot. But once you have run the tests with both 2.5 and 2.6 releasing is just a question of running python setup.py sdist register upload and it doesn't matter what Python version you use to run that. | 1 | 5 | 0 | I've got several eggs I maintain on Pypi but up until now I've always focused on Python 2.5x.
I'd like to release my eggs under both Python 2.5 & Python 2.6 in an automated fashion i.e.
running tests
generating doc
preparing eggs
uploading to Pypi
How do you guys achieve this?
A related question: how do I tag an egg to be "version independent" ? works under all version of Python? | Python Pypi: what is your process for releasing packages for different Python versions? (Linux) | 1.2 | 0 | 0 | 817 |
1,513,038 | 2009-10-03T07:04:00.000 | 1 | 0 | 0 | 1 | iphone,python,web-services,google-app-engine | 1,514,062 | 2 | false | 1 | 0 | Looks like you're not setting the Content-Type header correctly in your service (assuming you ARE actually trying to send XML -- e.g. SOAP, XML-RPC, &c). What code are you using to set that header? Without some indication about what protocol you're implementing and via what framework, it's impossible to help in detail...! | 2 | 0 | 0 | We made a simple application and using GoogleAppEngineLauncher (GAEL) ran that locally. Then we deployed, using GAEL again, to our appid. It works fine.
Now, we made a web service. We ran that locally using GAEL and a very thin local python client. It works fine.
We deployed that, and we get this message when we try to visit our default page:
"Move along people, there is nothing to see here"
We modified our local client and tried to run that against our google site and we got an error that looked like:
Response is "text/plain", not "text/xml"
Any ideas where we are falling down in our deployment or config for using a web service with google app engine?
Any help appreciated!
Thanks // :) | Deploying a web service to my Google App Engine application | 0.099668 | 0 | 0 | 369 |
1,513,038 | 2009-10-03T07:04:00.000 | 0 | 0 | 0 | 1 | iphone,python,web-services,google-app-engine | 1,604,138 | 2 | true | 1 | 0 | Looks like we aren't going to get to the bottom of this one. Just not enough information available at debug time. We've managed to affect a fix on the service, although I hate ot admit it we never found out what was causing this bug. | 2 | 0 | 0 | We made a simple application and using GoogleAppEngineLauncher (GAEL) ran that locally. Then we deployed, using GAEL again, to our appid. It works fine.
Now, we made a web service. We ran that locally using GAEL and a very thin local python client. It works fine.
We deployed that, and we get this message when we try to visit our default page:
"Move along people, there is nothing to see here"
We modified our local client and tried to run that against our google site and we got an error that looked like:
Response is "text/plain", not "text/xml"
Any ideas where we are falling down in our deployment or config for using a web service with google app engine?
Any help appreciated!
Thanks // :) | Deploying a web service to my Google App Engine application | 1.2 | 0 | 0 | 369 |
1,513,062 | 2009-10-03T07:17:00.000 | 9 | 1 | 0 | 0 | python,wordpress,drupal,content-management-system,social-networking | 1,513,657 | 6 | true | 0 | 0 | Difficult decision. Normally I would say 'definitely Drupal' without hesitation, as Drupal was build as a System for community sites from the beginning, whereas Wordpress still shows its heritage as a blogging solution, at least that's what I hear quite often. But then I'm working with Drupal all the time recently and haven't had a closer look at Wordpress for quite a while.
That said, Drupal has grown into a pretty complex system over the years, so there is quite a learning curve for newcomers. Given that you are already familiar with Wordpress, it might be more efficient for you to go with that, provided it can do all that you need.
So I would recommend Drupal, but you should probably get some opinions from people experienced with Wordpress concerning the possibility to turn it into a community site first.
As for the Python vs. PHP CMS question, I'd say that the quality of a CMS is a function of the ability of its developers, the maturity of the system, the surrounding 'ecosystem', etc. and not of the particular language used to build it. (And discussions about the quality of one established language vs. another? Well - let's just not go there ;) | 1 | 2 | 0 | I am making a community for web-comic artist who will be able to sync their existing website to this site.
However, I am in debate for what CMS I should use: Drupal or Wordpress.
I have heard great things about Drupal, where it is really aimed for Social Networking. I actually got to play a little bit in the back end of Drupal and it seemed quite complicated to me, but I am not going to give up to fully understand how Drupal works.
As for Wordpress, I am very familiar with the Framework. I have the ability to extend it to do what I want, but I am hesitating because I think the framework is not built for communities (I think it may slow down in the future).
I also have a unrelated question as well: Should I go with a Python CMS?
I heard very great things about Python and how much better it is compare to PHP.
Your advice is appreciated. | Drupal or Wordpress CMS as a Social Network? | 1.2 | 0 | 1 | 3,472 |
1,513,543 | 2009-10-03T11:40:00.000 | 0 | 1 | 0 | 0 | python,openid,rpxnow | 1,513,794 | 1 | true | 0 | 0 | I believe that OpenID lets the user decide how much information to "share" during the login process. I can't say that I am an expert on the subject, but I know that my identity at myopenid.com lets me specify precisely what information to make available.
Is it possible that the AOL default is to share nothing? If this is the case, then you may want to do an email authorization directly with the user if the OpenID provider doesn't seem to have the information. OpenID doesn't mandate that this information is available so I would assume that you will have to handle the case of it not being there in application code. | 1 | 0 | 0 | I can't seem to fetch the verifiedEmail field when trying to login to AOLs OpenID on my site. Every other provider that I know of provides this property, but not AOL.
I realize that AOL somehow uses an old OpenID version, although is it feasible to just assume that their e-mail ends in @aol.com? I'm using the RPXNow library with Python. | verifiedEmail AOL OpenID | 1.2 | 0 | 0 | 166 |
1,513,823 | 2009-10-03T14:08:00.000 | 2 | 0 | 0 | 0 | python,mechanize | 1,513,899 | 3 | false | 1 | 0 | Some wild ideas:
Fetch the second page before filling in the form?
Or fetch the new page and then goBack()? Although maybe that will reset the values. | 1 | 3 | 0 | There is a Python mechanize object with a form with almost all values set, but not yet submitted. Now I want to fetch another page using cookies from mechanize instance, but without resetting the page, forms and so on, e.g. so that the values remain set (I just need to get body string of another page, nothing else). So is there a way to:
Tell mechanize not to reset the page (perhaps, through UserAgentBase)?
Make urllib2 use mechanize's cookie jar? NB: urllib2.HTTPCookieProcessor(self.br._ua_handlers["_cookies"].cookiejar) doesn't work
Any other way to pass cookie to urllib? | How to get a http page using mechanize cookies? | 0.132549 | 0 | 1 | 1,699 |
1,514,228 | 2009-10-03T16:40:00.000 | 3 | 1 | 1 | 0 | python,data-persistence,dynamic-import | 1,514,234 | 5 | false | 0 | 0 | The biggest drawback is that it's a potential security problem since it's hard to guarantee that the files won't contains arbitrary code, which could be really bad. So don't use this approach if anyone else than you have write-access to the files. | 3 | 3 | 0 | This is what I've done for a project. I have a few data structures that are bascially dictionaries with some methods that operate on the data. When I save them to disk, I write them out to .py files as code that when imported as a module will load the same data into such a data structure.
Is this reasonable? Are there any big disadvantages? The advantage I see is that when I want to operate with the saved data, I can quickly import the modules I need. Also, the modules can be used seperate from the rest of the application because you don't need a separate parser or loader functionality. | Is it reasonable to save data as python modules? | 0.119427 | 0 | 0 | 351 |
1,514,228 | 2009-10-03T16:40:00.000 | 3 | 1 | 1 | 0 | python,data-persistence,dynamic-import | 1,514,248 | 5 | true | 0 | 0 | It's reasonable, and I do it all the time. Obviously it's not a format you use to exchange data, so it's not a good format for anything like a save file.
But for example, when I do migrations of websites to Plone, I often get data about the site (such as a list of which pages should be migrated, or a list of how old urls should be mapped to new ones, aor lists of tags). These you typically get in Word och Excel format. Also the data often needs massaging a bit, and I end up with what for all intents and purposes are a dictionaries mapping one URL to some other information.
Sure, I could save that as CVS, and parse it into a dictionary. But instead I typically save it as a Python file with a dictionary. Saves code.
So, yes, it's reasonable, no it's not a format you should use for any sort of save file. It however often used for data that straddles the border to configuration, like above. | 3 | 3 | 0 | This is what I've done for a project. I have a few data structures that are bascially dictionaries with some methods that operate on the data. When I save them to disk, I write them out to .py files as code that when imported as a module will load the same data into such a data structure.
Is this reasonable? Are there any big disadvantages? The advantage I see is that when I want to operate with the saved data, I can quickly import the modules I need. Also, the modules can be used seperate from the rest of the application because you don't need a separate parser or loader functionality. | Is it reasonable to save data as python modules? | 1.2 | 0 | 0 | 351 |
1,514,228 | 2009-10-03T16:40:00.000 | 7 | 1 | 1 | 0 | python,data-persistence,dynamic-import | 1,514,250 | 5 | false | 0 | 0 | By operating this way, you may gain some modicum of convenience, but you pay many kinds of price for that. The space it takes to save your data, and the time it takes to both save and reload it, go up substantially; and your security exposure is unbounded -- you must ferociously guard the paths from which you reload modules, as it would provide an easy avenue for any attacker to inject code of their choice to be executed under your userid (pickle itself is not rock-solid, security-wise, but, compared to this arrangement, it shines;-).
All in all, I prefer a simpler and more traditional arrangement: executable code lives in one module (on a typical code-loading path, that does not need to be R/W once the module's compiled) -- it gets loaded just once and from an already-compiled form. Data live in their own files (or portions of DB, etc) in any of the many suitable formats, mostly standard ones (possibly including multi-language ones such as JSON, CSV, XML, ... &c, if I want to keep the option open to easily load those data from other languages in the future). | 3 | 3 | 0 | This is what I've done for a project. I have a few data structures that are bascially dictionaries with some methods that operate on the data. When I save them to disk, I write them out to .py files as code that when imported as a module will load the same data into such a data structure.
Is this reasonable? Are there any big disadvantages? The advantage I see is that when I want to operate with the saved data, I can quickly import the modules I need. Also, the modules can be used seperate from the rest of the application because you don't need a separate parser or loader functionality. | Is it reasonable to save data as python modules? | 1 | 0 | 0 | 351 |
1,514,755 | 2009-10-03T20:26:00.000 | 5 | 0 | 0 | 0 | python,django,cherrypy | 1,514,830 | 7 | false | 1 | 0 | CherryPy is web server "http framework", while Django supports web application front-to-end: it provides object-relational mapper, template, session management, automagically generates DB schema and all CRUD screens, and more. | 7 | 35 | 0 | CherryPy vs Django, which would you use and why? | CherryPy vs Django | 0.141893 | 0 | 0 | 26,287 |
1,514,755 | 2009-10-03T20:26:00.000 | 4 | 0 | 0 | 0 | python,django,cherrypy | 13,001,017 | 7 | false | 1 | 0 | I think they're both great, but I'm not a fan of full stack frameworks. CherryPy is a lot easier to use and much more flexible. | 7 | 35 | 0 | CherryPy vs Django, which would you use and why? | CherryPy vs Django | 0.113791 | 0 | 0 | 26,287 |
1,514,755 | 2009-10-03T20:26:00.000 | 45 | 0 | 0 | 0 | python,django,cherrypy | 1,514,816 | 7 | true | 1 | 0 | They're not exactly comparable. CherryPy provides url routing and a request/response abstraction, which makes prototyping very easy (although I find vanilla mod_python just as convenient). Django is a complete web application "stack", including a templating system and an object-relational mapper. | 7 | 35 | 0 | CherryPy vs Django, which would you use and why? | CherryPy vs Django | 1.2 | 0 | 0 | 26,287 |
1,514,755 | 2009-10-03T20:26:00.000 | 6 | 0 | 0 | 0 | python,django,cherrypy | 1,514,785 | 7 | false | 1 | 0 | I would use Django because of its large user base and existing modules (including the built-in admin interface) but I would imaging that CherryPy is more flexible than Django. You just have to look at the available options, figure out what you want to do and choose the platform that supports that the best. | 7 | 35 | 0 | CherryPy vs Django, which would you use and why? | CherryPy vs Django | 1 | 0 | 0 | 26,287 |
1,514,755 | 2009-10-03T20:26:00.000 | 6 | 0 | 0 | 0 | python,django,cherrypy | 1,514,768 | 7 | false | 1 | 0 | Django, because the community is so much larger. You'll find more 3rd-party modules you can use and you'll find much more support. | 7 | 35 | 0 | CherryPy vs Django, which would you use and why? | CherryPy vs Django | 1 | 0 | 0 | 26,287 |
1,514,755 | 2009-10-03T20:26:00.000 | 11 | 0 | 0 | 0 | python,django,cherrypy | 1,520,944 | 7 | false | 1 | 0 | Though e.e. coli has already provided the accepted answer (and a good one at that), one thing I'll say in favor of CherryPy is that it is also implements WSGI out of the box. What this means is that, unlike the mod_python approach mentioned (which I believe is still an Apache-only solution)*, it provides abstraction from your web server. If you are all Apache all the time, this isn't so much a win, but if you ever think you may want to try alternate web servers, such as Lighttpd, then you can swap your web server w/o also having to make adjustments in your Python app. This was a big win for me personally.
*I don't mention Django here because I'm not a Django user (I don't like "full stack" frameworks) and so will leave any comments regarding it to it's many fans - all of whom are more qualified than I to answer questions about it. | 7 | 35 | 0 | CherryPy vs Django, which would you use and why? | CherryPy vs Django | 1 | 0 | 0 | 26,287 |
1,514,755 | 2009-10-03T20:26:00.000 | 13 | 0 | 0 | 0 | python,django,cherrypy | 7,599,911 | 7 | false | 1 | 0 | Django is vast, and difficult to learn, functions, tags and what not, you will absolutely are a computational genius if you have figured Django out completely. "full-stack" means every thing is available, you just have to spend the time looking for it :(
CherryPy is light and clean and far less complex. Compare the starter tutorials 1pg vs 4pgs you know what I mean. Its the difference between the "full-stack" java and the light and easy perl.
PS: the Django admin interface ROCKS!! | 7 | 35 | 0 | CherryPy vs Django, which would you use and why? | CherryPy vs Django | 1 | 0 | 0 | 26,287 |
1,515,686 | 2009-10-04T05:35:00.000 | 2 | 0 | 0 | 0 | python,sockets,nonblocking | 1,515,698 | 4 | false | 0 | 0 | Why socket alone? It's so much simpler to use another standard library module, asyncore -- and if you can't, at the very least select!
If you're constrained by your homework's condition to only use socket, then I hope you can at least add threading (or multiprocessing), otherwise you're seriously out of luck -- you can make sockets with timeout, but juggling timing-out sockets without the needed help from any of the other obvious standard library modules (to support either async or threaded serving) is a serious mess indeed-y...;-). | 1 | 0 | 0 | Can someone please tell how to write a Non-Blocking server code using the socket library alone.Thanks | Non Blocking Server in Python | 0.099668 | 0 | 1 | 2,625 |
1,515,850 | 2009-10-04T07:45:00.000 | 0 | 0 | 1 | 0 | python,windows-xp | 1,515,858 | 5 | false | 0 | 0 | Why do you want to do it? Everything that's in 3.0 is in 2.6, you can use the new features in 3.0 with from __future__ import. Run 2.6 until you're ready to upgrade to 3.0 for everything, then upgrade. You're not intended to have multiple versions of Python on the same machine. If you really want to, you can specify alternative install directories, but I really don't see how it's worth the hassle. | 2 | 3 | 0 | What kind of setup do people use to run both python 2.6 and python 3.0 on the same windows machine? | how to run both python 2.6 and 3.0 on the same windows XP box? | 0 | 0 | 0 | 691 |
1,515,850 | 2009-10-04T07:45:00.000 | 1 | 0 | 1 | 0 | python,windows-xp | 1,515,971 | 5 | false | 0 | 0 | -You could use a batch file to launch with the appropriate version.
-Eclipse with pydev allows you to choose which version to launch with.
-Re-associate the .py/.pyw extension with your preferred version. | 2 | 3 | 0 | What kind of setup do people use to run both python 2.6 and python 3.0 on the same windows machine? | how to run both python 2.6 and 3.0 on the same windows XP box? | 0.039979 | 0 | 0 | 691 |
1,517,038 | 2009-10-04T18:23:00.000 | 0 | 1 | 1 | 0 | python,refresh,reload | 27,299,101 | 7 | false | 0 | 0 | I had the exact same issue creating a geoprocessing script for ArcGIS 10.2. I had a python toolbox script, a tool script and then a common script. I have a parameter for Dev/Test/Prod in the tool that would control which version of the code was run. Dev would run the code in the dev folder, test from test folder and prod from prod folder. Changes to the common dev script would not run when the tool was run from ArcCatalog. Closing ArcCatalog made no difference. Even though I selected Dev or Test it would always run from the prod folder.
Adding reload(myCommonModule) to the tool script resolved this issue. | 1 | 29 | 0 | This is a very basic question - but I haven't been able to find an answer by searching online.
I am using python to control ArcGIS, and I have a simple python script, that calls some pre-written code.
However, when I make a change to the pre-written code, it does not appear to result in any change. I import this module, and have tried refreshing it, but nothing happens.
I've even moved the file it calls to another location, and the script still works fine. One thing I did yesterday was I added the folder where all my python files are to the sys path (using sys.append('path') ), and I wonder if that made a difference.
Thanks in advance, and sorry for the sloppy terminology. | python refresh/reload | 0 | 0 | 0 | 106,481 |
1,517,259 | 2009-10-04T20:08:00.000 | 2 | 0 | 1 | 0 | python,keyboard-shortcuts,ipython | 1,517,291 | 1 | false | 0 | 0 | You say you have multiple instances installed -- are these all on different machines? What operating system(s) are they running? If you access them remotely, what operating system are you running?
Do you get to them using ssh? Do you run something like screen, either locally or remotely, or both? There are lots of things that can interfere with your terminal settings, especially when you're working remotely.
I'm almost certain that iPython doesn't have anything to do with it -- though you might want to check the version numbers, to see if working and non-working environments are running different versions.
More likely, it is something in the terminal emulation layer, but you'll likely have to do some detective work of your own to find out what piece is causing it.
Take it one step at a time -- try to cut from a local shell, to make sure that works. Then connect to a remote machine, and cut from that shell. Start screen, if that's your normal way of doing things, and test from that shell. Then start ipython. If it stops there, then see if you can find another application on the same machine that's linked against gnu readline, and try that. You may find that none of the console apps cut proplerly on that machine, or you may find that they work, but not under screen. Or you may find that something in the terminal settings stops everything from working as soon as you ssh in.
You may also have some luck. if you can find out what terminal the remote machine thinks you are using ( echo $TERM ) by copying the termcap file from a working machine to one that doesn't. That's a bit more involved for these forums, though -- I'd repost at that point on serverfault.com or superuser.com
I hope that at least gives you a starting place -- terminals are finicky, and difficult to get right. Most people seem to not bother, as long as everything mostly works. | 1 | 0 | 0 | I use IPython very frequently and happily. Somehow, cutting text from the shell using the keyboard shortcut, Ctrl + X, is broken. Actually, I have a few different installations of IPython. In some of the installations, the shortcut works; in the others, it doesn't work.
What might be the reason for this? Where should I look into? | Cutting text from IPython shell using Ctrl-X is broken | 0.379949 | 0 | 0 | 274 |
1,517,347 | 2009-10-04T20:48:00.000 | 10 | 0 | 1 | 0 | python,algorithm,sorting,python-internals | 1,517,357 | 3 | false | 0 | 0 | In early python-versions, the sort function implemented a modified version of quicksort.
However, it was deemed unstable and as of 2.3 they switched to using an adaptive mergesort algorithm. | 1 | 128 | 1 | What algorithm is the built in sort() method in Python using? Is it possible to have a look at the code for that method? | About Python's built in sort() method | 1 | 0 | 0 | 71,971 |
1,517,428 | 2009-10-04T21:29:00.000 | 1 | 0 | 1 | 0 | c#,python,vim,ide | 1,517,444 | 11 | false | 0 | 0 | Good IDE for python are Komodo or Eclipse with PyDev.
But even Notepad++ or any other text editor will enough to get you started, since you don't need to compile your code, just have a good editor.
The benefit of the above IDEs, is that you can use them to manage a large scale project and debug your code.
As for the cross platform issue, as long as you don't use the specific os libs (such as win32api), you are safe in being cross platform.
Seems like a very large project for a first time. Is it going to be web based or desktop? Since it will greatly change your design and choice of python libs. | 2 | 2 | 0 | I'm locked in using C# and I don't like it one bit. I have to start branching out to better myself as a professional and as a person, so I've decided to start making things in my own time using Python.
The problem is, I've basically programmed only in C#. What IDE should I use to make programs using Python?
My goal is to make a sort of encyclopedic program for a game I'm playing right now, displaying hero information, names, stats, picture, etc. All of this information I'm going to parse from an XML file.
My plan is for this application to be able to run under Windows, Linux and Mac (I'm under the impression that any code written in Python works 100% cross-platform, right?)
Thanks a lot for your tremendous help brothers of SO. :P
Edit:
I guess I should clarify that I'm looking for an IDE that supports drag and drop GUI design. I'm used to using VS and I'm not really sure how you can do it any other way. | Coming from a Visual Studio background, what do you recommend I use to start my VERY FIRST Python project? | 0.01818 | 0 | 0 | 619 |
1,517,428 | 2009-10-04T21:29:00.000 | 0 | 0 | 1 | 0 | c#,python,vim,ide | 1,517,475 | 11 | false | 0 | 0 | Eclipse + Pydev is currently the gold standard IDE for Python. It's cross platform and since it's a general purpose IDE it has support for just about every other programming activity you might want to consider.
Eclipse is not bad for C++, and very mature for Java developers. It's quite amazing when you realize that all this great stuff costs nothing. | 2 | 2 | 0 | I'm locked in using C# and I don't like it one bit. I have to start branching out to better myself as a professional and as a person, so I've decided to start making things in my own time using Python.
The problem is, I've basically programmed only in C#. What IDE should I use to make programs using Python?
My goal is to make a sort of encyclopedic program for a game I'm playing right now, displaying hero information, names, stats, picture, etc. All of this information I'm going to parse from an XML file.
My plan is for this application to be able to run under Windows, Linux and Mac (I'm under the impression that any code written in Python works 100% cross-platform, right?)
Thanks a lot for your tremendous help brothers of SO. :P
Edit:
I guess I should clarify that I'm looking for an IDE that supports drag and drop GUI design. I'm used to using VS and I'm not really sure how you can do it any other way. | Coming from a Visual Studio background, what do you recommend I use to start my VERY FIRST Python project? | 0 | 0 | 0 | 619 |
1,517,771 | 2009-10-05T00:26:00.000 | 12 | 0 | 0 | 0 | python,sqlite | 1,517,795 | 3 | false | 0 | 0 | Generally, you do this by stringifying the list (with repr()), and then saving the string. On reading the string from the database, use eval() to re-create the list. Be careful, though that you are certain no user-generated data can get into the column, or the eval() is a security risk. | 1 | 12 | 0 | I want 3 columns to have 9 different values, like a list in Python.
Is it possible? If not in SQLite, then on another database engine? | Is it possible to save a list of values into a SQLite column? | 1 | 1 | 0 | 25,012 |
1,518,699 | 2009-10-05T07:40:00.000 | 1 | 0 | 0 | 1 | python,linux | 1,518,829 | 6 | false | 0 | 0 | When an USB device is plugged in syslog writes messages concerning this to /var/log/messages. The "dmesg" command shows this log. You can check near the end of the log to see which channel the device was attached to, it is usually /dev/sd(letter)(number) depending on the partitions and number of serial disks plugged into the system. | 3 | 5 | 0 | How can I detect when a flash drive is plugged in? I'm using a bare Debian installation, without any GUI and want to be notified in my Python script when a new flash drive appears... I know that D-BUS distributes such information, but i dont want to use D-BUS. Is there a more bare access to that information? Shouldn't that be available under /proc or /sys? How can I "connect" to that source?
Bye
falstaff | How can I detect when a flash drive is plugged in under Linux? | 0.033321 | 0 | 0 | 6,498 |
1,518,699 | 2009-10-05T07:40:00.000 | 0 | 0 | 0 | 1 | python,linux | 16,370,716 | 6 | false | 0 | 0 | I did this using zenity in a script and udev with rule on rhel6 with:
KERNEL=="sd[b-d]", DRIVERS=="usb", ACTION=="add", RUN+="/path/to/script" | 3 | 5 | 0 | How can I detect when a flash drive is plugged in? I'm using a bare Debian installation, without any GUI and want to be notified in my Python script when a new flash drive appears... I know that D-BUS distributes such information, but i dont want to use D-BUS. Is there a more bare access to that information? Shouldn't that be available under /proc or /sys? How can I "connect" to that source?
Bye
falstaff | How can I detect when a flash drive is plugged in under Linux? | 0 | 0 | 0 | 6,498 |
1,518,699 | 2009-10-05T07:40:00.000 | 0 | 0 | 0 | 1 | python,linux | 1,518,728 | 6 | false | 0 | 0 | /proc/partitions shows all the partitions known to the kernel. | 3 | 5 | 0 | How can I detect when a flash drive is plugged in? I'm using a bare Debian installation, without any GUI and want to be notified in my Python script when a new flash drive appears... I know that D-BUS distributes such information, but i dont want to use D-BUS. Is there a more bare access to that information? Shouldn't that be available under /proc or /sys? How can I "connect" to that source?
Bye
falstaff | How can I detect when a flash drive is plugged in under Linux? | 0 | 0 | 0 | 6,498 |
1,518,725 | 2009-10-05T07:50:00.000 | 0 | 0 | 0 | 0 | python,google-app-engine,bulk-load | 1,519,020 | 2 | false | 1 | 0 | I think you're going to need to be more specific as to what problem you're having. As far as bulk loading goes, there's lots of bulkloader documentation around; or are you asking about model design? If so, we need to know more about how you plan to search for users. Do you need partial string matches? Sorting? Fuzzy matching? | 1 | 0 | 0 | Hi I want some help in building a Phone book application on python and put it on google app engine. I am running a huge db of 2 million user lists and their contacts in phonebook. I want to upload all that data from my servers directly onto the google servers and then use a UI to retrieve the phone book contacts of each user based on his name.
I am using MS SQL sever 2005 as my DB.
Please help in putting together this application.
Your inputs are much appreciated. | Need help in designing a phone book application on python running on google app engine | 0 | 1 | 0 | 420 |
1,519,074 | 2009-10-05T09:37:00.000 | 0 | 0 | 0 | 0 | python,ssl | 1,520,341 | 4 | false | 0 | 0 | It is impossible to verify a self-signed certificate because of its very nature: it is self-signed.
You have to sign a certificate by some other trusted third party's certificate to be able to verify anything, and after this you can add that third party's certificate to the list of your trusted CAs and then you will be able to verify certificates signed by that certificate/CA.
If you want recommendations about how to do this in Python, you should provide the name of the SSL library you are using, since there is a choice of SSL libraries for Python. | 1 | 9 | 0 | I was trying to find out how I can go about verifying a self-signed certificate by a server in python. I could not find much data in google. I also want to make sure that the server url
Thanks in advance for any insights. | Verifying peer in SSL using python | 0 | 0 | 1 | 6,958 |
1,520,234 | 2009-10-05T13:56:00.000 | 0 | 0 | 0 | 0 | python,numpy,version | 53,898,417 | 17 | false | 0 | 0 | It is good to know the version of numpy you run, but strictly speaking if you just need to have specific version on your system you can write like this:
pip install numpy==1.14.3 and this will install the version you need and uninstall other versions of numpy. | 2 | 340 | 1 | How can I check which version of NumPy I'm using? | How do I check which version of NumPy I'm using? | 0 | 0 | 0 | 514,245 |
1,520,234 | 2009-10-05T13:56:00.000 | 11 | 0 | 0 | 0 | python,numpy,version | 46,330,631 | 17 | false | 0 | 0 | You can try this:
pip show numpy | 2 | 340 | 1 | How can I check which version of NumPy I'm using? | How do I check which version of NumPy I'm using? | 1 | 0 | 0 | 514,245 |
1,520,576 | 2009-10-05T14:52:00.000 | 0 | 0 | 1 | 0 | python,vim | 1,520,822 | 4 | false | 0 | 0 | Try hitting Ctrl-p while typing mid-word. Ctrl-p inserts the most recent word that starts with the prefix you're typing and Ctrl-n inserts the next match. If you have several possibilities, you can hit ctrl-p more than once to substitute each candidate in order. | 2 | 4 | 0 | I've gotten omnicompletion with Pysmell to work before, but I can't seem to do it again.
I tried following some steps online, but most, if not all, of them are to vague and assume too much that you know what you are doing to some extent.
Can someone post a full, step-by-step tutorial on how to get code completion working properly, for complete Vim newbies (for dummies?)? | Getting proper code completion for Python on Vim? | 0 | 0 | 0 | 7,163 |
1,520,576 | 2009-10-05T14:52:00.000 | 4 | 0 | 1 | 0 | python,vim | 1,523,392 | 4 | false | 0 | 0 | There's also Ctrl+n in insert mode which will autocomplete based on the words it has seen in any of the open buffers (even in other tabs). | 2 | 4 | 0 | I've gotten omnicompletion with Pysmell to work before, but I can't seem to do it again.
I tried following some steps online, but most, if not all, of them are to vague and assume too much that you know what you are doing to some extent.
Can someone post a full, step-by-step tutorial on how to get code completion working properly, for complete Vim newbies (for dummies?)? | Getting proper code completion for Python on Vim? | 0.197375 | 0 | 0 | 7,163 |
1,520,953 | 2009-10-05T16:04:00.000 | 0 | 0 | 0 | 1 | python,comet | 1,751,708 | 3 | false | 1 | 0 | Extending what lost-theory has said, if you want to use comet for a passing messages between clients then you need to implement something like pubsub.
Using something like tornado for the pubsub is much simpler than with the single threaded wsgiref servers. | 2 | 1 | 0 | I'm developing a web interface for an already existing desktop application. I've been looking for a way to allow the server to push content to the browser and ended up reaching Comet.
Navigating through the internet, and most of the questions here, I got answers like twisted, orbited, tornado and most of them even point to java applications like Jetty or StreamHub.
Without going too much deeper in this, I'd like to know is there's a chance to implement Comet-like communication using just standard lib modules like BaseHTTPServer and keep things as simple as possible as I don't need so much power and efficiency.
Note: Jython is a possibility, but I'd like to keep it with as less requirements as possible. | Basic Comet in Python using just std lib | 0 | 0 | 0 | 719 |
1,520,953 | 2009-10-05T16:04:00.000 | 0 | 0 | 0 | 1 | python,comet | 1,520,980 | 3 | false | 1 | 0 | This is possible. Just don't close the connection to the client. | 2 | 1 | 0 | I'm developing a web interface for an already existing desktop application. I've been looking for a way to allow the server to push content to the browser and ended up reaching Comet.
Navigating through the internet, and most of the questions here, I got answers like twisted, orbited, tornado and most of them even point to java applications like Jetty or StreamHub.
Without going too much deeper in this, I'd like to know is there's a chance to implement Comet-like communication using just standard lib modules like BaseHTTPServer and keep things as simple as possible as I don't need so much power and efficiency.
Note: Jython is a possibility, but I'd like to keep it with as less requirements as possible. | Basic Comet in Python using just std lib | 0 | 0 | 0 | 719 |
1,521,670 | 2009-10-05T18:28:00.000 | 1 | 0 | 0 | 0 | python,com,wxpython,parent | 1,522,240 | 2 | false | 0 | 0 | How's PP's control flow? If it's event-driven it could get appropriate events upon closure of that parent window or termination of that AP process; otherwise it could "poll" to check if the window or process are still around. | 1 | 0 | 0 | I have a Python program (PP) that loads another Program(AP) via COM, gets its window handle and sets it to be the PP parent.
This works pretty well except that I can't control that AP still has their [X] button available in the top left corner. Since this is a pretty obvious place for the user to close when they are done with the program, I tried this and it left the PP in the Task Manager running, but not visible with no possible way to kill it other than through Task Manager. Any ideas on how to handle this? I expect it to be rather Common that the user closes in this manner.
Thanks! | Close Python when Parent is closed | 0.099668 | 0 | 0 | 181 |
1,522,636 | 2009-10-05T21:59:00.000 | 6 | 0 | 0 | 0 | python,urllib | 1,522,662 | 5 | false | 0 | 0 | Strictly speaking, this is true. But in practice, once (if) urllib goes out of scope, the connection will be closed by the automatic garbage collector. | 2 | 73 | 0 | I'm new to Python and reading someone else's code:
should urllib.urlopen() be followed by urllib.close()? Otherwise, one would leak connections, correct? | should I call close() after urllib.urlopen()? | 1 | 0 | 1 | 53,885 |
1,522,636 | 2009-10-05T21:59:00.000 | 1 | 0 | 0 | 0 | python,urllib | 55,125,414 | 5 | false | 0 | 0 | You basically do need to explicitly close your connection when using IronPython. The automatic closing on going out of scope relies on the garbage collection. I ran into a situation where the garbage collection did not run for so long that Windows ran out of sockets. I was polling a webserver at high frequency (i.e. as high as IronPython and the connection would allow, ~7Hz). I could see the "established connections" (i.e. sockets in use) go up and up on PerfMon. The solution was to call gc.collect() after every call to urlopen. | 2 | 73 | 0 | I'm new to Python and reading someone else's code:
should urllib.urlopen() be followed by urllib.close()? Otherwise, one would leak connections, correct? | should I call close() after urllib.urlopen()? | 0.039979 | 0 | 1 | 53,885 |
1,522,844 | 2009-10-05T23:02:00.000 | 2 | 0 | 0 | 0 | python,django,fastcgi,lighttpd,flup | 1,531,138 | 2 | true | 1 | 0 | I've looked at this on django running as fastcgi on both Slicehost (django 1.1, python 2.6) and Dreamhost (django 1.0, python 2.5), and I can say this:
Running the top command shows the processes use a large amount of CPU to start up for ~2-3 seconds, then drop down to 0 almost immediately.
Running the ps aux command after starting the django app shows something similar to what you describe, however this is actually misleading. From the Ubuntu man pages for ps:
CPU usage is currently expressed as
the percentage of time spent running
during the entire lifetime of a
process. This is not ideal, and it
does not conform to the standards that
ps otherwise conforms to. CPU usage is
unlikely to add up to exactly 100%.
Basically, the %CPU column shown by ps is actually an average over the time the process has been running. The decay you see is due to the high initial spike followed by inactivity being averaged over time. | 2 | 1 | 0 | I'm running Django as threaded fastcgi via flup, served by lighttpd, communicating via sockets.
What is the expected CPU usage for each fastcgi thread under no load? On startup, each thread runs at 3-4% cpu usage for a while, and then backs off to around .5% over the course of a couple of hours. It doesn't sink below this level.
Is this much CPU usage normal? Do I have some bug in my code that is causing the idle loop to require more processing than it should? I expected the process to use no measurable CPU when it was completely idle.
I'm not doing anything ridiculously complicated with Django, definitely nothing that should require extended processing. I realize that this isn't a lot of load, but if it's a bug I introduced, I would like to fix it. | flup/fastcgi cpu usage under no-load conditions | 1.2 | 0 | 0 | 792 |
1,522,844 | 2009-10-05T23:02:00.000 | 0 | 0 | 0 | 0 | python,django,fastcgi,lighttpd,flup | 1,526,653 | 2 | false | 1 | 0 | Your fast-cgi threads must not consume any (noticeable) CPU if there are no requests to process.
You should investigate the load you are describing. I use the same architecture and my threads are completely idle. | 2 | 1 | 0 | I'm running Django as threaded fastcgi via flup, served by lighttpd, communicating via sockets.
What is the expected CPU usage for each fastcgi thread under no load? On startup, each thread runs at 3-4% cpu usage for a while, and then backs off to around .5% over the course of a couple of hours. It doesn't sink below this level.
Is this much CPU usage normal? Do I have some bug in my code that is causing the idle loop to require more processing than it should? I expected the process to use no measurable CPU when it was completely idle.
I'm not doing anything ridiculously complicated with Django, definitely nothing that should require extended processing. I realize that this isn't a lot of load, but if it's a bug I introduced, I would like to fix it. | flup/fastcgi cpu usage under no-load conditions | 0 | 0 | 0 | 792 |
1,522,951 | 2009-10-05T23:43:00.000 | 2 | 0 | 0 | 0 | php,python,html,dropbox | 2,074,899 | 3 | false | 1 | 0 | If you can install the DropBox client on the webserver then it would be simple to let it sync your folder and then iterate over the contents of the folder with a programming language (PHP, Python, .NET etc) and produce the gallery page. This could be done every time the page is requested or as a scheduled job which recreayes a static page. This is all dependent on you having access to install the client on your server. | 1 | 2 | 0 | I'd like to know if the following situation and scripts are at all possible:
I'm looking to have a photo-gallery (Javascript) webpage that will display in order of the latest added to the Dropbox folder (PHP or Python?).
That is, when someone adds a picture to the Dropbox folder, there is a script on the webpage that will check the Dropbox folder and then embed those images onto the webpage via the newest added and the webpage will automatically be updated.
Is it at all possible to link to a Dropbox folder via a webpage? If so, how would I best go about using scripts to automate the process of updating the webpage with new content?
Any and all help is very appreciated, thanks! | Update a gallery webpage via Dropbox? | 0.132549 | 0 | 1 | 4,092 |
1,523,465 | 2009-10-06T03:37:00.000 | -5 | 0 | 1 | 0 | python,binary | 49,278,853 | 10 | false | 0 | 0 | x = x + 1
print(x)
a = x + 5
print(a) | 5 | 105 | 0 | How can I add, subtract, and compare binary numbers in Python without converting to decimal? | Binary numbers in Python | -1 | 0 | 0 | 228,134 |
1,523,465 | 2009-10-06T03:37:00.000 | -1 | 0 | 1 | 0 | python,binary | 71,345,969 | 10 | false | 0 | 0 | For example, 00000011 - 00000001 = 00000010
You can remove the zeroes and then add them again after you do your calculation! This works very easy.
If your binary is stored as a string then you can convert to int which will automatically strip the zeroes from the start. After you have your answer you can turn it back into a string and add the zeroes to the start. | 5 | 105 | 0 | How can I add, subtract, and compare binary numbers in Python without converting to decimal? | Binary numbers in Python | -0.019997 | 0 | 0 | 228,134 |
1,523,465 | 2009-10-06T03:37:00.000 | 10 | 0 | 1 | 0 | python,binary | 1,523,478 | 10 | false | 0 | 0 | I think you're confused about what binary is. Binary and decimal are just different representations of a number - e.g. 101 base 2 and 5 base 10 are the same number. The operations add, subtract, and compare operate on numbers - 101 base 2 == 5 base 10 and addition is the same logical operation no matter what base you're working in. The fact that your python interpreter may store things as binary internally doesn't affect how you work with it - if you have an integer type, just use +, -, etc.
If you have strings of binary digits, you'll have to either write your own implementation or convert them using the int(binaryString, 2) function. | 5 | 105 | 0 | How can I add, subtract, and compare binary numbers in Python without converting to decimal? | Binary numbers in Python | 1 | 0 | 0 | 228,134 |
1,523,465 | 2009-10-06T03:37:00.000 | 3 | 0 | 1 | 0 | python,binary | 1,523,477 | 10 | false | 0 | 0 | Binary, decimal, hexadecimal... the base only matters when reading or outputting numbers, adding binary numbers is just the same as adding decimal number : it is just a matter of representation. | 5 | 105 | 0 | How can I add, subtract, and compare binary numbers in Python without converting to decimal? | Binary numbers in Python | 0.059928 | 0 | 0 | 228,134 |
1,523,465 | 2009-10-06T03:37:00.000 | -7 | 0 | 1 | 0 | python,binary | 33,672,372 | 10 | false | 0 | 0 | I think you're confused about what binary is. Binary and decimal are just different representations of a number - e.g. 101 base 2 and 5 base 10 are the same number. The operations add, subtract, and compare operate on numbers - 101 base 2 == 5 base 10 and addition is the same logical operation no matter what base you're working in. | 5 | 105 | 0 | How can I add, subtract, and compare binary numbers in Python without converting to decimal? | Binary numbers in Python | -1 | 0 | 0 | 228,134 |
1,523,706 | 2009-10-06T05:13:00.000 | 1 | 0 | 0 | 1 | python,python-3.x,werkzeug | 1,622,505 | 3 | false | 1 | 0 | I can only answer question one:
I started using it for some small webstuff but now moved on to rework larger apps with it. Why Werkzeug? The modular concept is really helpful. You can hook in modules as you like, make stuff easily context aware and you get good request file handling for free which is able to cope with 300mb+ files by not storing it in memory.
Disadvantages... Well sometimes modularity needs some upfront thought (django f.ex. gives you everything all at once, stripping stuff out is hard to do there though) but for me it works fine. | 3 | 2 | 0 | I've been looking really hard at all of the way**(s)** one can develop web applications using Python. For reference, we are using RHEL 64bit, apache, mod_wsgi.
History:
PHP + MySQL years ago
PHP + Python 2.x + MySQL recently and current
Python + PostgreSQL working on it
We use a great library for communicating between PHP and Python (interface in PHP, backend in Python)... However, with a larger upcoming project starting, using 100% python may be very advantagous.
We typically prefer not to have a monolithic framework dictating how things are done. A collection of useful helpers and utilities are much preferred (be it PHP or Python).
Question 1:
In reading a number of answers from experienced Python users, I've seen Werkzeug recommended a number of times. I would love it if several people with direct experience using Werkzeug to develop professional web applications could comment (in as much detail as their fingers feel like) why they use it, why they like it, and anything to watch out for.
Question 2:
Is there a version of Werkzeug that supports Python 3.1.1. I've succefully installed mod_wsgi on Apache 2.2 with Python 3.1.1.
If there is not a version, what would it take to upgrade it to work on Python 3.1?
Note: I've run 2to3 on the Werkzeug source code, and it does python-compile without
Edit:
The project that we are starting is not slated to be finished until nearly a year from now. At which point, I'm guessing Python 3.X will be a lot more mainstream. Furthermore, considering that we are running the App (not distributing it), can anyone comment on the viability of bashing through some of the Python 3 issues now, so that when a year from now arrives, we are more-or-less already there?
Thoughts appreciated! | Werkzeug in General, and in Python 3.1 | 0.066568 | 1 | 0 | 2,259 |
1,523,706 | 2009-10-06T05:13:00.000 | 1 | 0 | 0 | 1 | python,python-3.x,werkzeug | 1,523,934 | 3 | false | 1 | 0 | I haven't used Werkzeug, so I can only answer question 2:
No, Werkzeug does not work on Python 3. In fact, very little works on Python 3 as of today. Porting is not difficult, but you can't port until all your third-party libraries have been ported, so progress is slow.
One big stopper has been setuptools, which is a very popular package to use. Setuptools is unmaintained, but there is a maintained fork called Distribute. Distribute was released with Python 3 support just a week or two ago. I hope package support for Python 3 will pick up now. But it will still be a long time, at least months probably a year or so, before any major project like Werkzeug will be ported to Python 3. | 3 | 2 | 0 | I've been looking really hard at all of the way**(s)** one can develop web applications using Python. For reference, we are using RHEL 64bit, apache, mod_wsgi.
History:
PHP + MySQL years ago
PHP + Python 2.x + MySQL recently and current
Python + PostgreSQL working on it
We use a great library for communicating between PHP and Python (interface in PHP, backend in Python)... However, with a larger upcoming project starting, using 100% python may be very advantagous.
We typically prefer not to have a monolithic framework dictating how things are done. A collection of useful helpers and utilities are much preferred (be it PHP or Python).
Question 1:
In reading a number of answers from experienced Python users, I've seen Werkzeug recommended a number of times. I would love it if several people with direct experience using Werkzeug to develop professional web applications could comment (in as much detail as their fingers feel like) why they use it, why they like it, and anything to watch out for.
Question 2:
Is there a version of Werkzeug that supports Python 3.1.1. I've succefully installed mod_wsgi on Apache 2.2 with Python 3.1.1.
If there is not a version, what would it take to upgrade it to work on Python 3.1?
Note: I've run 2to3 on the Werkzeug source code, and it does python-compile without
Edit:
The project that we are starting is not slated to be finished until nearly a year from now. At which point, I'm guessing Python 3.X will be a lot more mainstream. Furthermore, considering that we are running the App (not distributing it), can anyone comment on the viability of bashing through some of the Python 3 issues now, so that when a year from now arrives, we are more-or-less already there?
Thoughts appreciated! | Werkzeug in General, and in Python 3.1 | 0.066568 | 1 | 0 | 2,259 |
1,523,706 | 2009-10-06T05:13:00.000 | 3 | 0 | 0 | 1 | python,python-3.x,werkzeug | 1,525,943 | 3 | false | 1 | 0 | mod_wsgi for Python 3.x is also not ready. There is no satisfactory definition of WSGI for Python 3.x yet; the WEB-SIG are still bashing out the issues. mod_wsgi targets a guess at what might be in it, but there are very likely to be changes to both the spec and to standard libraries. Any web application you write today in Python 3.1 is likely to break in the future.
It's a bit of a shambles. Today, for webapps you can only realistically use Python 2.x. | 3 | 2 | 0 | I've been looking really hard at all of the way**(s)** one can develop web applications using Python. For reference, we are using RHEL 64bit, apache, mod_wsgi.
History:
PHP + MySQL years ago
PHP + Python 2.x + MySQL recently and current
Python + PostgreSQL working on it
We use a great library for communicating between PHP and Python (interface in PHP, backend in Python)... However, with a larger upcoming project starting, using 100% python may be very advantagous.
We typically prefer not to have a monolithic framework dictating how things are done. A collection of useful helpers and utilities are much preferred (be it PHP or Python).
Question 1:
In reading a number of answers from experienced Python users, I've seen Werkzeug recommended a number of times. I would love it if several people with direct experience using Werkzeug to develop professional web applications could comment (in as much detail as their fingers feel like) why they use it, why they like it, and anything to watch out for.
Question 2:
Is there a version of Werkzeug that supports Python 3.1.1. I've succefully installed mod_wsgi on Apache 2.2 with Python 3.1.1.
If there is not a version, what would it take to upgrade it to work on Python 3.1?
Note: I've run 2to3 on the Werkzeug source code, and it does python-compile without
Edit:
The project that we are starting is not slated to be finished until nearly a year from now. At which point, I'm guessing Python 3.X will be a lot more mainstream. Furthermore, considering that we are running the App (not distributing it), can anyone comment on the viability of bashing through some of the Python 3 issues now, so that when a year from now arrives, we are more-or-less already there?
Thoughts appreciated! | Werkzeug in General, and in Python 3.1 | 0.197375 | 1 | 0 | 2,259 |
1,523,874 | 2009-10-06T06:17:00.000 | 1 | 1 | 0 | 1 | python,c,packaging,distutils | 1,523,993 | 2 | true | 0 | 0 | distutils can be used to install end user programs, but it's most useful when using it for Python libraries, as it can create source packages and also install them in the correct place. For that I would say it's more or less required.
But for an end user Python program you can also use make or whatever you like and are used to, as you don't need to install any code in the Python site-packages directory, and you don't need to put your code onto PyPI and it doesn't need to be accessible from other Python-code.
I don't think distutils will be neither more or less complicated to use in installing an end-user program compared to other tools. All such install/packaging tools are hella-complex, as Cartman would have said. | 2 | 0 | 0 | I have an open source project containing both Python and C code. I'm wondering that is there any use for distutils for me, because I'm planning to do a ubuntu/debian package. The C code is not something that I could or want to use as Python extension. C and Python programs communicate with TCP/IP through localhost.
So the bottom line here is that while I'm learning packaging, does the usage of distutils specific files only make me more confused since I can't use my C-code as Python extensions? Or should I divide my C and Python functionality to separate projects to be able to understand packaging concepts better? | Reasons to use distutils when packaging C/Python project | 1.2 | 0 | 0 | 284 |
1,523,874 | 2009-10-06T06:17:00.000 | 1 | 1 | 0 | 1 | python,c,packaging,distutils | 1,525,194 | 2 | false | 0 | 0 | Because it uses an unified python setup.py install command? distutils, or setuptools? Whatever, just use one of those.
For development, it's also really useful because you don't have to care where to find such and such dependency. As long as it's standard Python/basic system library stuff, setup.py should find it for you. With setup.py, you don't require anymore ./configure stuff or ugly autotools to create huge Makefiles. It just works (tm) | 2 | 0 | 0 | I have an open source project containing both Python and C code. I'm wondering that is there any use for distutils for me, because I'm planning to do a ubuntu/debian package. The C code is not something that I could or want to use as Python extension. C and Python programs communicate with TCP/IP through localhost.
So the bottom line here is that while I'm learning packaging, does the usage of distutils specific files only make me more confused since I can't use my C-code as Python extensions? Or should I divide my C and Python functionality to separate projects to be able to understand packaging concepts better? | Reasons to use distutils when packaging C/Python project | 0.099668 | 0 | 0 | 284 |
1,524,606 | 2009-10-06T09:45:00.000 | 0 | 0 | 0 | 0 | c#,python,ruby | 1,524,622 | 1 | false | 1 | 0 | Applet should be better if your application is not depended on IE.
If for IE only then use COM/ActiveX | 1 | 0 | 0 | Can I use applets to inform me which hardware is installed on client system (fingerprint reader)? And if it is installed, can it tell me its version, so that it can download the proper plugin from a site? So that after everything is OK, the user can use his fingerprint reader to authenticate himself? | Is an applet a proper solution for hardware detection and driver install? | 0 | 0 | 0 | 101 |
1,524,609 | 2009-10-06T09:47:00.000 | 2 | 0 | 1 | 0 | c#,python,programming-languages,boo | 1,524,626 | 5 | false | 0 | 0 | You have lists and dictionaries in .Net: System.Collections.Generic.List and System.collections.Generic.Dictionary.
As for the language: Just learn the one that is more fun for you. The choice of language is most often religious. Expecially on the .Net platform, where each language has almost the same capabilities. | 3 | 11 | 0 | Compared to C#, Boo feels a bit more Pythonic but it's also compiled down to .NET MSIL. I liked its syntax, even more than C#'s syntax. But I couldn't find a single book teaching Boo.
And I really don't know, if learning Boo is better than C# or learning C# is better than Boo. I just want to use some Python-like data types. Those are:
{key1:value1, key2:value2} β dictionary
[Value1,Value2,Value3] β List (can be edited/changed)
(Value1,Value2,Value3) β Tuple (can't be edited/changed)
I use dictionaries more than list and tuples. I want to know, which one is better? | Boo vs C# vs Python? | 0.07983 | 0 | 0 | 15,993 |
1,524,609 | 2009-10-06T09:47:00.000 | 5 | 0 | 1 | 0 | c#,python,programming-languages,boo | 1,524,633 | 5 | false | 0 | 0 | My general opinion is that it would be better to go for C# since it is from my point of view, easier to find resources, documentation and tutorials for C#. | 3 | 11 | 0 | Compared to C#, Boo feels a bit more Pythonic but it's also compiled down to .NET MSIL. I liked its syntax, even more than C#'s syntax. But I couldn't find a single book teaching Boo.
And I really don't know, if learning Boo is better than C# or learning C# is better than Boo. I just want to use some Python-like data types. Those are:
{key1:value1, key2:value2} β dictionary
[Value1,Value2,Value3] β List (can be edited/changed)
(Value1,Value2,Value3) β Tuple (can't be edited/changed)
I use dictionaries more than list and tuples. I want to know, which one is better? | Boo vs C# vs Python? | 0.197375 | 0 | 0 | 15,993 |
1,524,609 | 2009-10-06T09:47:00.000 | 15 | 0 | 1 | 0 | c#,python,programming-languages,boo | 1,525,499 | 5 | true | 0 | 0 | I have found Boo to be very useful in creating simple one-off scripts, while retaining my Pythonic source style. And since it compiles to runnable EXE or DLL, I can package up a single EXE with all the needed DLLs (including Boo.Lang.dll) using ILMerge, and then send that off to a client, usually for some kind of quick troubleshooting or system diagnosis.
I also use Boo to support my C# development. I often fire up a Boo interpreter to try out variations of string or date formatting, then I can replicate the final version almost directly into C#.
But it is darned difficult to find docs for Boo. I had to Google quite a bit to find the syntax for generics, since they are a relatively new addition to Boo, and not yet mentioned in any tutorials, or even reference pages. And googling for "boo" generates quite a few unwanted hits, making the search even more difficult.
So in short, don't make this a choice between Boo and C# - they actually complement each other pretty well. | 3 | 11 | 0 | Compared to C#, Boo feels a bit more Pythonic but it's also compiled down to .NET MSIL. I liked its syntax, even more than C#'s syntax. But I couldn't find a single book teaching Boo.
And I really don't know, if learning Boo is better than C# or learning C# is better than Boo. I just want to use some Python-like data types. Those are:
{key1:value1, key2:value2} β dictionary
[Value1,Value2,Value3] β List (can be edited/changed)
(Value1,Value2,Value3) β Tuple (can't be edited/changed)
I use dictionaries more than list and tuples. I want to know, which one is better? | Boo vs C# vs Python? | 1.2 | 0 | 0 | 15,993 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.