Q_Id int64 337 49.3M | CreationDate stringlengths 23 23 | Users Score int64 -42 1.15k | Other int64 0 1 | Python Basics and Environment int64 0 1 | System Administration and DevOps int64 0 1 | Tags stringlengths 6 105 | A_Id int64 518 72.5M | AnswerCount int64 1 64 | is_accepted bool 2
classes | Web Development int64 0 1 | GUI and Desktop Applications int64 0 1 | Answer stringlengths 6 11.6k | Available Count int64 1 31 | Q_Score int64 0 6.79k | Data Science and Machine Learning int64 0 1 | Question stringlengths 15 29k | Title stringlengths 11 150 | Score float64 -1 1.2 | Database and SQL int64 0 1 | Networking and APIs int64 0 1 | ViewCount int64 8 6.81M |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
2,273,414 | 2010-02-16T14:06:00.000 | 1 | 0 | 0 | 0 | python,sql,mysql,tdd,automated-tests | 2,273,471 | 2 | true | 0 | 0 | I'd do both. Run against the small set first to make sure all the code works, then run against the large dataset for things which need to be tested for time, this would be selects, searches and reports especially. If you are doing inserts or deletes or updates on multiple row sets, I'd test those as well against the large set. It is unlikely that simple single row action queries will take too long, but if they involve a lot alot of joins, I'd test them as well. If the queries won't run on prod within the timeout limits, that's a fail and far, far better to know as soon as possible so you can fix before you bring prod to it's knees. | 2 | 1 | 0 | I am developing some Python modules that use a mysql database to insert some data and produce various types of report. I'm doing test driven development and so far I run:
some CREATE / UPDATE / DELETE tests against a temporary database that is thrown away at the end of each test case, and
some report generation tests doing exclusively read only operations, mainly SELECT, against a copy of the production database, written on the (valid, in this case) assumption that some things in my database aren't going to change.
Some of the SELECT operations are running slow, so that my tests are taking more than 30 seconds, which spoils the flow of test driven development. I can see two choices:
only put a small fraction of my data into the copy of the production database that I use for testing the report generation so that the tests go fast enough for test driven development (less than about 3 seconds suits me best), or I can regard the tests as failures. I'd then need to do separate performance testing.
fill the production database copy with as much data as the main test database, and add timing code that fails a test if it is taking too long.
I'm not sure which approach to take. Any advice? | Should pre-commit tests use a big data set and fail if queries take too long, or use a small test database? | 1.2 | 1 | 0 | 107 |
2,273,414 | 2010-02-16T14:06:00.000 | 1 | 0 | 0 | 0 | python,sql,mysql,tdd,automated-tests | 2,273,476 | 2 | false | 0 | 0 | The problem with testing against real data is that it contains lots of duplicate values, and not enough edge cases. It is also difficult to know what the expected values ought to be (especially if your live database is very big). Oh, and depending on what the live application does, it can be illegal to use the data for the purposes of testing or development.
Generally the best thing is to write the test data to go with the tests. This is labourious and boring, which is why so many TDD practitioners abhor databases. But if you have a live data set (which you can use for testing) then take a very cut-down sub-set of data for your tests. If you can write valid assertions against a dataset of thirty records, running your tests against a data set of thirty thousand is just a waste of time.
But definitely, once you have got the queries returning the correct results put the queries through some performance tests. | 2 | 1 | 0 | I am developing some Python modules that use a mysql database to insert some data and produce various types of report. I'm doing test driven development and so far I run:
some CREATE / UPDATE / DELETE tests against a temporary database that is thrown away at the end of each test case, and
some report generation tests doing exclusively read only operations, mainly SELECT, against a copy of the production database, written on the (valid, in this case) assumption that some things in my database aren't going to change.
Some of the SELECT operations are running slow, so that my tests are taking more than 30 seconds, which spoils the flow of test driven development. I can see two choices:
only put a small fraction of my data into the copy of the production database that I use for testing the report generation so that the tests go fast enough for test driven development (less than about 3 seconds suits me best), or I can regard the tests as failures. I'd then need to do separate performance testing.
fill the production database copy with as much data as the main test database, and add timing code that fails a test if it is taking too long.
I'm not sure which approach to take. Any advice? | Should pre-commit tests use a big data set and fail if queries take too long, or use a small test database? | 0.099668 | 1 | 0 | 107 |
2,273,462 | 2010-02-16T14:14:00.000 | 1 | 0 | 1 | 0 | python,regex,string,split,uppercase | 2,273,756 | 5 | false | 0 | 0 | So 'words' in this case are:
Any number of uppercase letters - unless the last uppercase letter is followed by a lowercase letter.
One uppercase letter followed by any number of lowercase letters.
so try:
([A-Z]+(?![a-z])|[A-Z][a-z]*)
The first alternation includes a negative lookahead (?![a-z]), which handles the boundary between an all-caps word and an initial caps word. | 2 | 4 | 0 | I would like to replace strings like 'HDMWhoSomeThing' to 'HDM Who Some Thing' with regex.
So I would like to extract words which starts with an upper-case letter or consist of upper-case letters only. Notice that in the string 'HDMWho' the last upper-case letter is in the fact the first letter of the word Who - and should not be included in the word HDM.
What is the correct regex to achieve this goal? I have tried many regex' similar to [A-Z][a-z]+ but without success. The [A-Z][a-z]+ gives me 'Who Some Thing' - without 'HDM' of course.
Any ideas?
Thanks,
Rukki | Regex divide with upper-case | 0.039979 | 0 | 0 | 2,370 |
2,273,462 | 2010-02-16T14:14:00.000 | 2 | 0 | 1 | 0 | python,regex,string,split,uppercase | 2,273,759 | 5 | false | 0 | 0 | one liner :
' '.join(a or b for a,b in re.findall('([A-Z][a-z]+)|(?:([A-Z]*)(?=[A-Z]))',s))
using regexp
([A-Z][a-z]+)|(?:([A-Z]*)(?=[A-Z])) | 2 | 4 | 0 | I would like to replace strings like 'HDMWhoSomeThing' to 'HDM Who Some Thing' with regex.
So I would like to extract words which starts with an upper-case letter or consist of upper-case letters only. Notice that in the string 'HDMWho' the last upper-case letter is in the fact the first letter of the word Who - and should not be included in the word HDM.
What is the correct regex to achieve this goal? I have tried many regex' similar to [A-Z][a-z]+ but without success. The [A-Z][a-z]+ gives me 'Who Some Thing' - without 'HDM' of course.
Any ideas?
Thanks,
Rukki | Regex divide with upper-case | 0.07983 | 0 | 0 | 2,370 |
2,274,068 | 2010-02-16T15:46:00.000 | 1 | 0 | 1 | 0 | ironpython | 2,278,532 | 1 | true | 0 | 0 | My guess is you're using a version of pyc.py against a version of IronPython for which it is not intended. The latest versions of IronPython include pyc.py in the Tools\Scripts directory of the installation dir. | 1 | 1 | 0 | AttributeError: attribute "CompilerSink" of "namespace#" object is read-only | Error in IronPython Command Line Compiler | 1.2 | 0 | 0 | 189 |
2,275,043 | 2010-02-16T17:50:00.000 | 2 | 0 | 0 | 0 | python,django | 2,275,652 | 2 | true | 1 | 0 | The User model has a lot of dependencies and must conform to a diverse set of API requirements in order to interoperate with the rest of the django framework. This is because of its relationship with authentication and authorization. Changing User means changing the expected behavior of contrib.auth. If you want to do that, you can, and that is configurable in settings.py.
More likely, what you want to configure is the extra metadata that relates with users. This extra info isn't in any way involved with authentication, and so it can be configured separately without affecting contrib.auth. In order to make the dependencies easy to manage, this is handled in a separate model. This has the added benefit of making the distinction between authorization dependent data and site specific user metadata much clearer. | 2 | 0 | 0 | Why doesn't django just have the model to use for User configured in the settings file?
The requirements on the model specified would be that it contain a certain set of fields.
Is there a reason why it couldn't be done this way? | Why does django not do for the User model the same as it does for the userprofile model? | 1.2 | 0 | 0 | 89 |
2,275,043 | 2010-02-16T17:50:00.000 | 0 | 0 | 0 | 0 | python,django | 2,275,208 | 2 | false | 1 | 0 | "Why doesn't django just have the model to use for User configured in the settings file?"
I have a site that doesn't need users or a login or authentication.
I don't want the model for User.
In order to support everyone with applications like mine, User is optional. | 2 | 0 | 0 | Why doesn't django just have the model to use for User configured in the settings file?
The requirements on the model specified would be that it contain a certain set of fields.
Is there a reason why it couldn't be done this way? | Why does django not do for the User model the same as it does for the userprofile model? | 0 | 0 | 0 | 89 |
2,276,000 | 2010-02-16T20:15:00.000 | 4 | 1 | 0 | 0 | python | 2,276,041 | 6 | false | 1 | 0 | One of the lightest-weight frameworks is mod_wsgi. Anything less is going to be a huge amount of work parsing HTTP requests to find headers and URI's and methods and parsing the GET or POST query/data association, handling file uploads, cookies, etc.
As it is, mod_wsgi will only handle the basics of request parsing and framing up results.
Sessions, cookies, using a template generator for your response pages will be a surprising amount of work.
Once you've started down that road, you may find that a little framework support goes a long way. | 1 | 43 | 0 | I am just starting Python and I was wondering how I would go about programming web applications without the need of a framework. I am an experienced PHP developer but I have an urge to try out Python and I usually like to write from scratch without the restriction of a framework like flask or django to name a few. | Program web applications in python without a framework? | 0.132549 | 0 | 0 | 35,567 |
2,276,117 | 2010-02-16T20:33:00.000 | 5 | 0 | 1 | 0 | python,multiprocessing,virtual-machine | 2,276,333 | 2 | false | 0 | 0 | If you ignore any communication issues (i.e., if the separate Python VMs do not communicate among themselves, or communicate only through other mechanisms that are explicitly established), there are no other substantial differences. (I believe multiprocessing, under certain conditions -- Unix-like platforms, in particular -- can use the more efficient fork rather than the fork-exec pair always implied by multiprocessing -- but that's not "substantial" when just a few processes are involved [[IOW, the performance difference on startup will not be material to the performance of the whole system]]). | 2 | 17 | 0 | Aside from the ease of use of the multiprocessing module when it comes to hooking up processes with communication resources, are there any other differences between spawning multiple processes using multiprocessing compared to using subprocess to launch separate Python VMs ? | Python multiprocessing process vs. standalone Python VM | 0.462117 | 0 | 0 | 5,857 |
2,276,117 | 2010-02-16T20:33:00.000 | 22 | 0 | 1 | 0 | python,multiprocessing,virtual-machine | 2,276,366 | 2 | true | 0 | 0 | On Posix platforms, multiprocessing primitives essentially wrap an os.fork(). What this means is that at point you spawn a process in multiprocessing, the code already imported/initialized remains so in the child process.
This can be a boon if you have a lot of things to initialize and then each subprocess essentially performs operations on (copies of) those initialized objects, but not all that helpful if the thing you run in the subprocess is completely unrelated.
There are also implications for resources such as file-handles, sockets, etc with multiprocessing on a unix-like platform.
Meanwhile, when using subprocess, you are creating an entirely new program/interpreter each time you Popen a new process. This means there can be less shared memory between them, but it also means you can Popen into a completely separate program, or a new entry-point into the same program.
On Windows, the differences are less between multiprocessing and subprocess, because windows does not provide fork(). | 2 | 17 | 0 | Aside from the ease of use of the multiprocessing module when it comes to hooking up processes with communication resources, are there any other differences between spawning multiple processes using multiprocessing compared to using subprocess to launch separate Python VMs ? | Python multiprocessing process vs. standalone Python VM | 1.2 | 0 | 0 | 5,857 |
2,276,235 | 2010-02-16T20:50:00.000 | 2 | 0 | 0 | 0 | python,gis,arcgis,gdal | 2,294,445 | 3 | false | 0 | 0 | ArcObjects and geoprocessing add a lot more functionality than GDAL and is mostly aimed at the desktop. Another option for looking at Python is also using QGIS which has a python API, is Free and Open Source, and an active developer community.
There are also plenty of python libraries for doing spatial work, such as Shapely. I would say for raster that GDAL is your best bet but for vector you might want to use something like shapely. | 1 | 3 | 0 | Im just starting off with GDAL + python to support operations that cannot be done with ArcGIS python geoprocessing scripting. Mainly I am doing spatial modeling/analysis/editing of raster and vector data.
I am a bit confused when ArcObject development is required versus when GDAL can be used?
Is there functionality of ArcObjects that GDAL does not do? Is the opposite true too?
I am assuming that ArcObjects are more useful in developing online tools versus Desktop analysis and modeling where the difference is more to do with preference? In my case i prefer GDAL because of python support, which I believe ArcObjects lack.
thanks! | GIS: When and why to use ArcObjects over GDAL programming to work with ArcGIS rasters and vectors? | 0.132549 | 0 | 0 | 3,379 |
2,276,512 | 2010-02-16T21:31:00.000 | 0 | 1 | 1 | 1 | python,windows,installation,path,python-3.x | 2,276,543 | 2 | false | 0 | 0 | Hmm, find the Lib dir from sys.path and extrapolate from there? | 1 | 1 | 0 | I need to access the Scripts and tcl sub-directories of the currently executing Python instance's installation directory on Windows.
What is the best way to locate these directories? | Path of current Python instance? | 0 | 0 | 0 | 590 |
2,276,800 | 2010-02-16T22:18:00.000 | 1 | 1 | 1 | 0 | python,properties,metaprogramming,automatic-properties | 2,277,257 | 4 | false | 0 | 0 | Be careful using magic, especially magically altering other people's bindings. This has the disadvantages that
Your code is incompatible with other people accessing the same library. Someone can't import one of your modules or copy and paste your code and have it work perfectly with their program accessing the same library, and
Your interface is different from the interface to the C++ code. This would make sense if your wrapper gave you a nicer, higher-level interface, but your changes are only trivial.
Consider whether it wouldn't make more sense just to deal with the library you are using as it came to you. | 1 | 4 | 0 | I have a big library written in C++ and someone created an interface to use it in python (2.6) in an automatic way. Now I have a lot of classes with getter and setter methods. Really: I hate them.
I want to re-implement the classes with a more pythonic interface using properties. The problem is that every class has hundreds of getters and setters and I have a lot of classes. How can I automatically create properties?
For example, if I have a class called MyClass with a GetX() and SetX(x), GetY, SetY, etc... methods, how can I automatically create a derived class MyPythonicClass with the property X (readable if there is the getter and writable if there is the setter), and so on? I would like a mechanism that lets me to choose to skip some getter/setter couples where it is better to do the work by hand. | Automatic transformation from getter/setter to properties | 0.049958 | 0 | 0 | 2,591 |
2,277,302 | 2010-02-16T23:50:00.000 | 11 | 0 | 0 | 0 | python,url,encoding | 2,277,313 | 3 | true | 0 | 0 | Take a look at urllib.unquote and urllib.unquote_plus. That will address your problem. Technically though url "encoding" is the process of passing arguments into a url with the & and ? characters (e.g. www.foo.com?x=11&y=12). | 1 | 11 | 0 | Given this:
It%27s%20me%21
Unencode it and turn it into regular text? | How do I url unencode in Python? | 1.2 | 0 | 1 | 5,032 |
2,277,571 | 2010-02-17T00:45:00.000 | 0 | 0 | 1 | 1 | c#,python,command-line | 7,886,740 | 2 | false | 0 | 0 | I had a similar issue, I solved it by adding raw_input() at the end of the script.
Even if it's not using the value the script should hold before quitting as it waits for input from the command line.
Sadly this doesn't help if the script errors out before it reaches the raw_input() line, but you'll see how far along it gets. | 1 | 1 | 0 | Now the obvious answer is to just open the script from a command line, but that isn't an option. I'm writing a simple application to syntax highlight Python and then run the scripts from the same program. A Python IDE if you will. The scripts I want to run are entirely command line programs.
I'm using a System.Diagnostics.Process object. I can either use it to run a command line prompt or to run the Python script, but the command line window will close as soon as the script errors or finishes. I need to keep it open. The ideal solution would be to open the command line and run the Python script from the command line, but I need to do it in one click from inside a .Net application.
Any ideas? Is there a better way to keep the console open? | How can I keep a Python script command window open when opened from a .Net application? | 0 | 0 | 0 | 797 |
2,277,895 | 2010-02-17T02:13:00.000 | 0 | 0 | 1 | 0 | python,dictionary,merge | 2,278,164 | 3 | false | 0 | 0 | If I understood your question correctly and you have integer ids for the words and corpora, then you can gain some performance by switching from a dict to a list, or even better, a numpy array. This may be annoying!
Basically, you need to replace the tuple with a single integer, which we can call the newid. You want all the newids to correspond to a word,corpus pair, so I would count the words in each corpus, and then have, for each corpus, a starting newid. The newid of (word,corpus) will then be word + start_newid[corpus].
If I misunderstood you and you don't have such ids, then I think this advice might still be useful, but you will have to manipulate your data to get it into the tuple of ints format.
Another thing you could try is rechunking the data.
Let's say that you can only hold 1.1 of these monsters in memory. Then, you can load one, and create a smaller dict or array that only corresponds to the first 10% of (word,corpus) pairs. You can scan through the loaded dict, and deal with any of the ones that are in the first 10%. When you are done, you can write the result back to disk, and do another pass for the second 10%. This will require 10 passes, but that might be OK for you.
If you chose your previous chunking based on what would fit in memory, then you will have to arbitrarily break your old dicts in half so that you can hold one in memory while also holding the result dict/array. | 1 | 2 | 0 | Sorry for the very general title but I'll try to be as specific as possible.
I am working on a text mining application. I have a large number of key value pairs of the form ((word, corpus) -> occurence_count) (everything is an integer) which I am storing in multiple python dictionaries (tuple->int). These values are spread across multiple files on the disk (I pickled them). To make any sense of the data, I need to aggregate these dictionaries Basically, I need to figure out a way to find all the occurrences of a particular key in all the dictionaries, and add them up to get a total count.
If I load more than one dictionary at a time, I run out of memory, which is the reason I had to split them in the first place. When I tried , I ran into performance issues. I am currently trying to store the values in a DB (mysql), processing multiple dictionaries at a time, since mysql provides row level locking, which is both good (since it means I can parallelize this operation) and bad (since it slows down the insert queries)
What are my options here? Is it a good idea to write a partially disk based dictionary so I can process the dicts one at a time? With an LRU replacement strategy? Is there something that I am completely oblivious to?
Thanks! | merging dictionaries in python | 0 | 0 | 0 | 1,000 |
2,278,228 | 2010-02-17T04:04:00.000 | 4 | 0 | 0 | 0 | c++,python,c,opencv | 10,057,553 | 4 | false | 0 | 1 | I think it depends how proficient you are in C++. The Mat interface does appear more modern than the old IPLImage C interface. The problem I'm having is that most of the examples you'll find on the web, or even here on stackoverflow are for the C interface (e.g. cvCvtColor), not for the C++ interface. So I'm really struggling to port the C examples to C++. | 3 | 27 | 0 | I was thinking of trying OpenCV for a project and noticed that it had C, C++ and Python.
I am trying to figure out whether I should use C++, C or Python -- and would like to use whatever has the best OpenCV support.
Just from looking at the index page for the various documentation it looks like the C++ bindings might have more features than the others? Is this true?
If C++ has more bindings, it seems that would be a more obvious choice for me, but I was just curious if it really has more features, etc than the others?
Thanks! | OpenCV Image Processing -- C++ vs C vs Python | 0.197375 | 0 | 0 | 7,757 |
2,278,228 | 2010-02-17T04:04:00.000 | 13 | 0 | 0 | 0 | c++,python,c,opencv | 2,278,331 | 4 | true | 0 | 1 | The Python interface is still being developed whereas the C++ interface (especially with the new Mat class) is quite mature. If you're comfortable in C++, I would highly recommend using it - else, you can start using Python and contribute back any features you think OpenCV needs :) | 3 | 27 | 0 | I was thinking of trying OpenCV for a project and noticed that it had C, C++ and Python.
I am trying to figure out whether I should use C++, C or Python -- and would like to use whatever has the best OpenCV support.
Just from looking at the index page for the various documentation it looks like the C++ bindings might have more features than the others? Is this true?
If C++ has more bindings, it seems that would be a more obvious choice for me, but I was just curious if it really has more features, etc than the others?
Thanks! | OpenCV Image Processing -- C++ vs C vs Python | 1.2 | 0 | 0 | 7,757 |
2,278,228 | 2010-02-17T04:04:00.000 | 1 | 0 | 0 | 0 | c++,python,c,opencv | 16,210,061 | 4 | false | 0 | 1 | Even if you're very proficient in C or C++, you should use python to speed up your development (I should guess a 4x factor). Performance are really quite the same. | 3 | 27 | 0 | I was thinking of trying OpenCV for a project and noticed that it had C, C++ and Python.
I am trying to figure out whether I should use C++, C or Python -- and would like to use whatever has the best OpenCV support.
Just from looking at the index page for the various documentation it looks like the C++ bindings might have more features than the others? Is this true?
If C++ has more bindings, it seems that would be a more obvious choice for me, but I was just curious if it really has more features, etc than the others?
Thanks! | OpenCV Image Processing -- C++ vs C vs Python | 0.049958 | 0 | 0 | 7,757 |
2,278,665 | 2010-02-17T06:06:00.000 | -1 | 0 | 0 | 1 | python,udp,twisted | 2,278,671 | 2 | false | 0 | 0 | Are you sure that it is not a receive problem?
There is no indication that your packets won't be fragmented en route to the destination | 2 | 1 | 0 | I would like to find out if Twisted imposes restriction on maximum size of UDP packets. The allowable limit on linux platforms is upto 64k (although I intend to send packets of about 10k bytes consisting of JPEG images) but I am not able to send more than approx. 2500 bytes | Question regarding UDP communication in twisted framework | -0.099668 | 0 | 0 | 435 |
2,278,665 | 2010-02-17T06:06:00.000 | 1 | 0 | 0 | 1 | python,udp,twisted | 2,280,167 | 2 | false | 0 | 0 | It's very unlikely that Twisted is imposing any limit but there's no reason some other part of the network wouldn't drop the packets if they're too large. It's very rare for people to send UDP packets of such a large size for precisely that sort of reason. Most game applications for example try to keep them below 1.5K these days, and below 512 bytes in the not-too-distant past. | 2 | 1 | 0 | I would like to find out if Twisted imposes restriction on maximum size of UDP packets. The allowable limit on linux platforms is upto 64k (although I intend to send packets of about 10k bytes consisting of JPEG images) but I am not able to send more than approx. 2500 bytes | Question regarding UDP communication in twisted framework | 0.099668 | 0 | 0 | 435 |
2,279,749 | 2010-02-17T10:11:00.000 | 0 | 0 | 0 | 1 | python,bash,curl,scripting,multiplatform | 2,301,977 | 2 | false | 0 | 0 | I thought Pycurl might be the answer. Ahh Daniel Sternberg and his innocent presumptions that everybody knows what he does. I asked on the list whether or not pycurl had a "curl -o" analogue, and then asked 'If so: How would one go about coding it/them in a Python script?' His reply was the following:
"curl.setopt(pycurl.WRITEDATA, fp)
possibly combined with:
curl.setopt(pycurl.WRITEFUNCITON, callback) "
...along with Sourceforge links to two revisions of retriever.py. I can barely recall where easy_install put the one I've got; how am I supposed to compare them?
It's pretty apparent this gentleman never had a helpdesk or phone tech support job in the Western Hemisphere, where you have to assume the 'customer' just learned how to use their comb yesterday and be prepared to walk them through everything and anything. One-liners (or three-liners with abstruse links as chasers) don't do it for me.
BZT | 1 | 4 | 0 | The particular alias I'm looking to "class up" into a Python script happens to be one that makes use of the cUrl -o (output to file) option. I suppose I could as easily turn it into a BASH function, but someone advised me that I could avoid the quirks and pitfalls of the different versions and "flavors" of BASH by taking my ideas and making them Python scripts.
Coincident with this idea is another notion I had to make a feature of legacy Mac OS (officially known as "OS 9" or "Classic") pertaining to downloads platform-independent: writing the URL to some part of the file visible from one's file navigator {Konqueror, Dolphin, Nautilus, Finder or Explorer}. I know that only a scant few file types support this kind of thing using some other command-line tools (exiv2, wrjpgcom, etc). Which is perfectly fine with me as I only use this alias to download single-page image files such as JPEGs anyways.
I reckon I might as well take full advantage of the power of Python by having the script pass the string which is the source URL of the download (entered by the user and used first by cUrl) to something like exiv2 which could write it to the Comment block, EXIF User Comment block, and (taking as a first and worst example) Windows XP's File Description field. Starting small is sometimes a good way to start.
Hope someone has advice or suggestions.
BZT | Bash alias to Python script -- is it possible? | 0 | 0 | 0 | 11,553 |
2,281,373 | 2010-02-17T14:23:00.000 | 0 | 0 | 0 | 0 | python,pygtk | 70,261,450 | 2 | false | 0 | 1 | If you don't want to see the object then you could button.set_visible(False) to hide it or button.set_visible(True) to show it. This will prevent users from seeing the button. | 1 | 18 | 0 | How can I set a gtk.Button enabled or disabled in PyGTK? | Enable or disable gtk.Button in PyGTK | 0 | 0 | 0 | 12,047 |
2,282,300 | 2010-02-17T16:14:00.000 | 1 | 0 | 1 | 0 | python,list,tuples | 2,282,328 | 2 | false | 0 | 0 | Tuples are immutable, they can't be modified. Convert it to a list, then convert it back if you want to (list((a, b))). | 1 | 3 | 0 | I have a list of tuples representing x,y points. I also have a list of values for each of these points. How do I combine them into a list of lists (i.e one entry for each point [x,y,val]) or a list of tuples?
Thanks | Adding an entry to a python tuple | 0.099668 | 0 | 0 | 928 |
2,282,360 | 2010-02-17T16:20:00.000 | 1 | 0 | 0 | 0 | java,python | 2,282,470 | 5 | false | 1 | 0 | The largest issue I can think of is the need to install an interpreter.
With Java, a lot of people will already have that interpreter installed, although you won't necessarily know which version. It may be wise to include the installer for Java with the program.
With Python, you're going to have to install the interpreter on each computer, too.
One commenter mentioned .NET. .NET 2.0 has a fairly high likelyhood of being installed than either Java or Python on Windows machines. The catch is that you can't (easily) install it on OSX or Linux. | 2 | 0 | 0 | I'm going to write my first non-Access project, and I need advice on choosing the platform. I will be installing it on multiple friends' and family's computers, so (since I'm sure many, many platforms would suffice just fine for my app), my highest priority has two parts: 1) ease of install for the non-technical user and, 2) minimizing compatibility problems. I want to be able to fix bugs and make changes and roll them out without having to troubleshoot OS and program conflicts on their computers (or at least keeping those things to the absolute minimum-this is why these concerns are my highest priority in choosing a platform.)
I have narrowed it down to Python or Java. I like Java's use of the JVM, which seems like would serve to protect against incompatibilities on individual computers nicely. And I've heard a lot of good things about Python, but I don't know how much more prone to incompatibilities it is vs Java. In case it is important, I know the app will definitely use some flavor of a free server-enabled SQL db (server-enabled because I want to be able to run the app from multiple computers), but I don't know which to use yet. I thought I could decide that next.
My experience level: I've taken a C++ (console app only) class and done some VBA in Access, but mostly I'm going to have to jump in and learn as I go. So of course I don't know much about all of this. I'm not in the computer field, this is just a hobby.
So, which would be better for this app, Java or Python?
(In case it comes up, I don't want to make it browser-based at all. I've dealt with individual computers' browser settings breaking programs, and that goes against part 2 of my top priority - maximum compatibility.)
Thank you.
Update: It will need a gui, and I'd like to be able to do a little bit of customization on it (or use a non-standard, or maybe a non-built-in one) to make it pop a little.
Update 2: Truthfully, I really am only concerned with Windows computers. I am considering Java only for its reliability as a platform. | Help for novice choosing between Java and Python for app with sql db | 0.039979 | 1 | 0 | 594 |
2,282,360 | 2010-02-17T16:20:00.000 | 1 | 0 | 0 | 0 | java,python | 2,283,347 | 5 | true | 1 | 0 | If you're going to install only (or mostly) on Windows, I'd go with .Net.
If you have experience with C++, then C# would be natural to you, but if you're comfortable with VBA, you can try VB.NET, but if you prefer Python, then there is IronPython or can give a try to IronRuby, but the best of all is you can mix them all as they apply to different parts of your project.
In the database area you'll have excellent integration with SQL Server Express, and in the GUI area, Swing can't beat the ease of use of WinForms nor the sophistication of WPF/Silverlight.
As an added bonus, you can have your application automatically updated with ClickOnce. | 2 | 0 | 0 | I'm going to write my first non-Access project, and I need advice on choosing the platform. I will be installing it on multiple friends' and family's computers, so (since I'm sure many, many platforms would suffice just fine for my app), my highest priority has two parts: 1) ease of install for the non-technical user and, 2) minimizing compatibility problems. I want to be able to fix bugs and make changes and roll them out without having to troubleshoot OS and program conflicts on their computers (or at least keeping those things to the absolute minimum-this is why these concerns are my highest priority in choosing a platform.)
I have narrowed it down to Python or Java. I like Java's use of the JVM, which seems like would serve to protect against incompatibilities on individual computers nicely. And I've heard a lot of good things about Python, but I don't know how much more prone to incompatibilities it is vs Java. In case it is important, I know the app will definitely use some flavor of a free server-enabled SQL db (server-enabled because I want to be able to run the app from multiple computers), but I don't know which to use yet. I thought I could decide that next.
My experience level: I've taken a C++ (console app only) class and done some VBA in Access, but mostly I'm going to have to jump in and learn as I go. So of course I don't know much about all of this. I'm not in the computer field, this is just a hobby.
So, which would be better for this app, Java or Python?
(In case it comes up, I don't want to make it browser-based at all. I've dealt with individual computers' browser settings breaking programs, and that goes against part 2 of my top priority - maximum compatibility.)
Thank you.
Update: It will need a gui, and I'd like to be able to do a little bit of customization on it (or use a non-standard, or maybe a non-built-in one) to make it pop a little.
Update 2: Truthfully, I really am only concerned with Windows computers. I am considering Java only for its reliability as a platform. | Help for novice choosing between Java and Python for app with sql db | 1.2 | 1 | 0 | 594 |
2,282,619 | 2010-02-17T16:52:00.000 | 2 | 0 | 0 | 0 | python,django,model-view-controller,frameworks | 2,282,645 | 4 | false | 1 | 0 | Well, I have a trivial solution - get used to reading the manual and the django book they host.
Django manual is organized well, and once you have a mental picture of it, you'll really be able to make a good use of it.
Two things I wish Django docs were better at - tell clearly where to import stuff right at each definition of class and sometimes I wish explanations were a little shorter. | 1 | 6 | 0 | I am looking for advice on best resources to learn how to develop webapps with Django [the python framework]. Here's a few information to help responders to narrow-down the gazillion options "out there".
Where I stand
I know python (2.x series) and I have developed a few applications/scripts with it. I wouldn't define myself a python-ninja in any way, but I think got a very good understanding of the language structure and - above all - philosophy.
I have PHP-only experience with web development.
I have fair understanding of MVC approach to frameworks (CakePHP) but not so much experience IRL.
What I am looking for
Structured learning material: book titles, online tutorials, videos, etc...
Life stories and personal accounts: how did you learn? why did you choose to learn that way? did it work? would you change anything in the way you learnt django?
Any kind of advice you think is worth sharing!
I would like to stress that I am not looking just for raw links (I could probably find those myself with google, after all!) but I am rather looking for your opinion and advice (with a link attached to them)!
Thank you in advance for your time! | Suggestions wanted: learning material for Django | 0.099668 | 0 | 0 | 514 |
2,283,034 | 2010-02-17T17:43:00.000 | 9 | 1 | 1 | 0 | python,perl | 2,286,686 | 7 | false | 0 | 0 | Being a hardcore Perl programmer, all I can say is DO NOT BUY O'Reilly's "Learning Python". It is nowhere NEAR as good as "Learning Perl", and there's no equivalent I know of to Larry Wall's "Programming Perl", which is simply unbeatable.
I've had the most success taking past Perl programs and translating them into Python, trying to make use of as many new techniques as possible. | 2 | 55 | 0 | I am an experienced Perl developer with some degree of experience and/or familiarity with other languages (working experience with C/C++, school experience with Java and Scheme, and passing familiarity with many others).
I might need to get some web work done in Python (most immediately, related to Google App Engine). As such, I'd like to ask SO overmind for good references on how to best learn Python for someone who's coming from Perl background (e.g. the emphasis would be on differences between the two and how to translate perl idiomatics into Python idiomatics, as opposed to generic Python references). Something also centered on Web development is even better.
I'll take anything - articles, tutorials, books, sample apps?
Thanks! | Python for a Perl programmer | 1 | 0 | 0 | 24,062 |
2,283,034 | 2010-02-17T17:43:00.000 | -4 | 1 | 1 | 0 | python,perl | 2,283,093 | 7 | false | 0 | 0 | I wouldn't try to compare Perl and Python too much in order to learn Python, especially since you have working knowledge of other languages. If you are unfamiliar with OOP/Functional programming aspects and just looking to work procedurally like in Perl, start learning the Python language constructs / syntax and then do a couple examples. if you are making a switch to OO or functional style paradigms, I would read up on OO fundamentals first, then start on Python syntax and examples...so you have a sort of mental blueprint of how things can be constructed before you start working with the actual materials. this is just my humble opinion however.. | 2 | 55 | 0 | I am an experienced Perl developer with some degree of experience and/or familiarity with other languages (working experience with C/C++, school experience with Java and Scheme, and passing familiarity with many others).
I might need to get some web work done in Python (most immediately, related to Google App Engine). As such, I'd like to ask SO overmind for good references on how to best learn Python for someone who's coming from Perl background (e.g. the emphasis would be on differences between the two and how to translate perl idiomatics into Python idiomatics, as opposed to generic Python references). Something also centered on Web development is even better.
I'll take anything - articles, tutorials, books, sample apps?
Thanks! | Python for a Perl programmer | -1 | 0 | 0 | 24,062 |
2,285,922 | 2010-02-18T02:37:00.000 | 0 | 0 | 1 | 0 | python,queue,multiprocessing | 2,286,094 | 1 | true | 0 | 0 | I don't believe multiprocessing sets up a "watch-dog" process for you to take care of crashes or kills of some of your processes. It may be worth your while to set one up (pretty hard to do cross-platform, but if, say, you're only worried about Linux, it's not that terrible). | 1 | 1 | 0 | I am using the multiprocessing python module with Queue for communication between processes. Some processes only send (i.e. queue.put) and I can't seem to find a way to detect when the receiving end gets terminated abruptly.
Is there a way to detect if the process at the other end of the Queue gets terminated without having to get from the Queue? Isn't there a signal I could trap somehow? Or do I have to periodically get from the Queue and trap the EOFError manually. | detection of communication failure when "put" in queue | 1.2 | 0 | 0 | 244 |
2,286,790 | 2010-02-18T06:48:00.000 | 2 | 0 | 0 | 0 | python,api,office-communicator | 3,754,769 | 3 | true | 0 | 0 | >>> import win32com.client
>>> msg = win32com.client.Dispatch('Communicator.UIAutomation')
>>> msg.InstantMessage('user@domain.com') | 1 | 2 | 0 | I want to use ms office communicator client apis, and i wan to use those in python is it possible to do ? | How can we use ms office communicator client exposed APIs in python, is that possible? | 1.2 | 0 | 1 | 1,868 |
2,286,860 | 2010-02-18T07:09:00.000 | 2 | 0 | 1 | 0 | python,algorithm | 2,286,874 | 19 | false | 0 | 0 | Keep an array of 256 "seen" booleans, one for each possible character.
Stream your string. If you haven't seen the character before, output it and set the "seen" flag for that character. | 3 | 5 | 0 | What is an efficient algorithm to removing all duplicates in a string?
For example : aaaabbbccdbdbcd
Required result: abcd | Removing duplicates in a string in Python | 0.02105 | 0 | 0 | 13,212 |
2,286,860 | 2010-02-18T07:09:00.000 | 0 | 0 | 1 | 0 | python,algorithm | 2,330,671 | 19 | false | 0 | 0 | This sounds like a perfect use for automata. | 3 | 5 | 0 | What is an efficient algorithm to removing all duplicates in a string?
For example : aaaabbbccdbdbcd
Required result: abcd | Removing duplicates in a string in Python | 0 | 0 | 0 | 13,212 |
2,286,860 | 2010-02-18T07:09:00.000 | 19 | 0 | 1 | 0 | python,algorithm | 2,286,870 | 19 | true | 0 | 0 | You use a hashtable to store currently discovered keys (access O(1)) and then loop through the array. If a character is in the hashtable, discard it. If it isn't add it to the hashtable and a result string.
Overall: O(n) time (and space).
The naive solution is to search for the character is the result string as you process each one. That O(n2). | 3 | 5 | 0 | What is an efficient algorithm to removing all duplicates in a string?
For example : aaaabbbccdbdbcd
Required result: abcd | Removing duplicates in a string in Python | 1.2 | 0 | 0 | 13,212 |
2,288,725 | 2010-02-18T13:00:00.000 | 0 | 0 | 0 | 1 | python,django,google-app-engine | 2,289,005 | 1 | true | 1 | 0 | I had module nammed same way as the default GAE launcher (main/ and main.py). After renaming the launcher everything works great. | 1 | 0 | 0 | I've downloaded google_appengine version 1.3.1. Using some web tutorials, I've created basic django 1.1.1 application. Using appcfg I managed to deploy it on GAE and it works. The problem is, that application doesn't want to work on dev_appengine.py developement server.
Whenever I run the app GAE local server is returning HTTP 200 without any content. If I set basic environement and run main.py manually, then the page is properly returned on stdout.
I've also created very basic helloworld application, and this one is working ok on the devel server.
Do you have any idea, how can I debug the devel server? Option -d doesn't give any usefull insight at all. | Problem with running Django 1.1.1 on Google App Engine Developement Server | 1.2 | 0 | 0 | 261 |
2,289,187 | 2010-02-18T14:16:00.000 | 0 | 0 | 0 | 0 | python,django | 2,289,931 | 7 | false | 1 | 0 | Hm, maybe you lie to manage.py, pretending to make fixtures, but only to look for apps:
apps=$(python manage.py makefixture 2>&1 | egrep -v '(^Error|^django)'|awk -F . '{print $2}'|uniq); for i in $apps; do python manage.py sqlreset $i; done| grep DROP
That prints out a list of DROP TABLE statements for all apps tables of your project, excluding django tables itself. If you want to include them, remove the |^django pattern vom egrep.
But how to feed the correct database backend? sed/awk-ing through settings.conf? Or better by utilizing a little settings.conf-reading python script itself. | 3 | 20 | 0 | How do I completely reset my Django (1.2 alpha) DB (dropping all tables, rather than just clearing them)?
manage.py flush does too little (won't work if there are schema changes) and manage.py reset requires me to specify all apps (and appears to take a format that is different from just " ".join(INSTALLED_APPS)). I can obviously achieve this in a DB specific way, but I figured there must be a sane, DB backend agnostic way to do this.
[Edit: I'm looking for something that I can call from a script, e.g. a Makefile and that continues to work if I change the backend DB or add to settings.INSTALLED_APPS] | Complete django DB reset | 0 | 1 | 0 | 24,412 |
2,289,187 | 2010-02-18T14:16:00.000 | 0 | 0 | 0 | 0 | python,django | 2,289,445 | 7 | false | 1 | 0 | Just assign a new database and drop this db from the db console. Seems to me to be the simplest. | 3 | 20 | 0 | How do I completely reset my Django (1.2 alpha) DB (dropping all tables, rather than just clearing them)?
manage.py flush does too little (won't work if there are schema changes) and manage.py reset requires me to specify all apps (and appears to take a format that is different from just " ".join(INSTALLED_APPS)). I can obviously achieve this in a DB specific way, but I figured there must be a sane, DB backend agnostic way to do this.
[Edit: I'm looking for something that I can call from a script, e.g. a Makefile and that continues to work if I change the backend DB or add to settings.INSTALLED_APPS] | Complete django DB reset | 0 | 1 | 0 | 24,412 |
2,289,187 | 2010-02-18T14:16:00.000 | -2 | 0 | 0 | 0 | python,django | 2,289,727 | 7 | false | 1 | 0 | take a look at reset command in django's code, and write your own which drops/creates DB first. | 3 | 20 | 0 | How do I completely reset my Django (1.2 alpha) DB (dropping all tables, rather than just clearing them)?
manage.py flush does too little (won't work if there are schema changes) and manage.py reset requires me to specify all apps (and appears to take a format that is different from just " ".join(INSTALLED_APPS)). I can obviously achieve this in a DB specific way, but I figured there must be a sane, DB backend agnostic way to do this.
[Edit: I'm looking for something that I can call from a script, e.g. a Makefile and that continues to work if I change the backend DB or add to settings.INSTALLED_APPS] | Complete django DB reset | -0.057081 | 1 | 0 | 24,412 |
2,291,714 | 2010-02-18T19:50:00.000 | 0 | 0 | 0 | 0 | python,mysql,django,exception | 55,394,190 | 5 | false | 1 | 0 | The exceptions in object destructors (__del__) are ignored, which this message indicates. If you execute some MySQL command without fetching results from the cursor (e.g. 'create procedure' or 'insert') then the exception is unnoticed until the cursor is destroyed.
If you want to raise and catch an exception, call explicitly cursor.close() somewhere before going out of the scope. | 3 | 8 | 0 | i'm using Python with MySQL and Django. I keep seeing this error and I can't figure out where the exception is being thrown:
Exception _mysql_exceptions.ProgrammingError: (2014, "Commands out of sync; you can't run this command now") in <bound method Cursor.__del__ of <MySQLdb.cursors.Cursor object at 0x20108150>> ignored
I have many "try" and "exception" blocks in my code--if the exception occurred within one of those, then I would see my own debugging messages. The above Exception is obviously being caught somewhere since my program does not abort when the Exception is thrown.
I'm very puzzled, can someone help me out? | Who is throwing (and catching) this MySQL Exception? | 0 | 1 | 0 | 6,125 |
2,291,714 | 2010-02-18T19:50:00.000 | 2 | 0 | 0 | 0 | python,mysql,django,exception | 2,300,154 | 5 | false | 1 | 0 | After printing out a bunch of stuff and debugging, I figured out the problem I think. One of the libraries that I used didn't close the connection or the cursor. But this problem only shows up if I iterate through a large amount of data. The problem is also very intermittent and I still don't know who's throwing the "command out of sync" exception. But now that we closed both the connection and cursor, I don't see the errors anymore. | 3 | 8 | 0 | i'm using Python with MySQL and Django. I keep seeing this error and I can't figure out where the exception is being thrown:
Exception _mysql_exceptions.ProgrammingError: (2014, "Commands out of sync; you can't run this command now") in <bound method Cursor.__del__ of <MySQLdb.cursors.Cursor object at 0x20108150>> ignored
I have many "try" and "exception" blocks in my code--if the exception occurred within one of those, then I would see my own debugging messages. The above Exception is obviously being caught somewhere since my program does not abort when the Exception is thrown.
I'm very puzzled, can someone help me out? | Who is throwing (and catching) this MySQL Exception? | 0.07983 | 1 | 0 | 6,125 |
2,291,714 | 2010-02-18T19:50:00.000 | 2 | 0 | 0 | 0 | python,mysql,django,exception | 2,292,145 | 5 | false | 1 | 0 | I believe this error can occur if you are using the same connection/cursor from multiple threads.
However, I dont think the creators of Django has made such a mistake, but if you are doing something by yourself it can easily happen. | 3 | 8 | 0 | i'm using Python with MySQL and Django. I keep seeing this error and I can't figure out where the exception is being thrown:
Exception _mysql_exceptions.ProgrammingError: (2014, "Commands out of sync; you can't run this command now") in <bound method Cursor.__del__ of <MySQLdb.cursors.Cursor object at 0x20108150>> ignored
I have many "try" and "exception" blocks in my code--if the exception occurred within one of those, then I would see my own debugging messages. The above Exception is obviously being caught somewhere since my program does not abort when the Exception is thrown.
I'm very puzzled, can someone help me out? | Who is throwing (and catching) this MySQL Exception? | 0.07983 | 1 | 0 | 6,125 |
2,292,775 | 2010-02-18T22:39:00.000 | 1 | 0 | 0 | 0 | python,ironpython | 2,292,804 | 3 | false | 1 | 0 | Django does in theory run on Windows, but using Apache and MySQL. It's not possible (and certainly not recommended) to run it on IIS.
I know you totally didn't ask this, but I have to advise that if you really want to get into Python web development then looking into a Linux technology stack is definitely the recommended approach. :) | 1 | 6 | 0 | I started learning Python using the IronPython implementation. I'd like to do some web development now. I'm looking for a python web development framework that works on the Microsoft technology stack (IIS + MS SQL Server). Django looks like an interesting framework but based on what I have read, getting it to work on the Microsoft technology stack seems very hard or not possible.
I want to lean a web framework that leverages python strengths, so ASP.NET is not an option here.
The reasons why I want to do Python on full Microsoft stack are:
We are a .Net shop and our production servers run the full Microsoft stack
With IronPython, I'll be able to interop with our product's existing .Net Libraries
Our existing database runs in SQL Server and I want to develop an app that queries that database
Deploying my Python projects to our server will not be allowed if I have to install another web server
Any recommendations? | What Python/IronPython web development framework work on the Microsoft technology stack? | 0.066568 | 0 | 0 | 1,847 |
2,293,273 | 2010-02-19T00:23:00.000 | 3 | 0 | 1 | 0 | ironpython | 2,299,777 | 1 | true | 0 | 0 | There's no built-in way to do this. But you could do this by hand. You can call GetItems() on the ScriptScope and then save all the values and then put all the values back into a new ScriptScope. | 1 | 4 | 0 | I'm using IronPython 2.6 and I was wondering if there was a way to copy a Microsoft.Scripting.Hosting.ScriptScope to get all the variables and context in another ScriptScope. The reason I want this is I am executing a file, and I want to restore the context to before the start of the execution if an exception occurs.
Thanks. | Copy ScriptScope? | 1.2 | 0 | 0 | 502 |
2,294,509 | 2010-02-19T06:36:00.000 | 1 | 0 | 1 | 0 | python,encoding | 2,294,548 | 2 | true | 0 | 0 | Are you using Python 3.X or 2.X? It makes a difference. Actually looks like 2.X but you confused me by using print(blahblah) :-)
Answer to your last question: Yes, ASCII by default when you do print(). On 3.X: Use print(ascii(foo)) for debugging, not print(foo). On 2.X use repr(), not ascii().
Your original problem with the no-break space should go away if (a) the data is unicode and (b) you use the re.UNICODE flag with the re.compile() | 1 | 1 | 0 | I'm having a problem when trying to apply a regular expression to some strings encoded in latin-1 (ISO-8859-1).
What I'm trying to do is send some data via HTTP POST from a page encoded in ISO-8859-1 to my python application and do some parsing on the data using regular expressions in my python script.
The web page uses jQuery to send the data to the server and I'm grabbing the text from the page using the .text() method. Once the data is sent back to the server looks like this: re.compile(r"^[\s,]*(\d*\s*\d*\/*\d)[\s,]*") - Unfortunately the \s in my regular expression is not matching my data, and I traced the problem down to the fact that the html page uses which gets encoded to 0xA0 (non-breaking space) and sent to the server. For some reason, it seems, my script is not interpreting that character as whitespace and is not matching. According to the python [documentation][1] it looks like this should work, so I must have an encoding issue here.
I then wanted to try converting the string into unicode and pass it to the regular expression, so I tried to view what would happen when I converted the string: print(unicode(data, 'iso-8859-1')).
Unfortunately I got this error:
UnicodeEncodeError at /script/
'ascii' codec can't encode character u'\xa0' in position 122: ordinal not in range(128)
I'm confused though - I'm obviously not trying to use ASCII decoding - is python trying to decode using ASCII even though I'm obviously passing another codec? | 'ASCII' to Unicode error in python when attempting to read a latin-1 encoded string | 1.2 | 0 | 0 | 955 |
2,294,956 | 2010-02-19T08:41:00.000 | 1 | 0 | 0 | 0 | python,qt,pyqt,qt-designer | 2,296,460 | 2 | false | 0 | 1 | Try finding pyuic3 or rather pyuic4. Since you are using PyQt all your qt tools have py in front (like pyrcc4 or pyuicc4).
I am not sure, that there are pyqt3 binaries for windows. Are you sure that Phil Thompson did PyQt3 also for windows at the time? If so, they would be on riverbank site, I guess, but I can't find them there. Tried compiling the source yourself? | 1 | 0 | 0 | I've a PyQt 4 installed (I can't find PyQt 3 for Windows) and I would like to open a QtDesigner ui file which has been created with QtDesigner 3.3.
When I open this file I've the following message:
Please use uic3 -convert to convert to Qt4
Unfortunately, I don't see the uic3 tool in the bin folder of my install.
Does anybody know how can I can convert this file to QtDesigner 4?
Additional quastion: Where to download PyQy3 binaries for Windows?
Thanks in advance | How to open a Pyqt 3.3 ui file with QtDesigner 4? | 0.099668 | 0 | 0 | 900 |
2,296,550 | 2010-02-19T13:28:00.000 | 3 | 0 | 1 | 0 | python,scope,global-variables | 2,298,388 | 3 | false | 0 | 0 | Python does not support globals shared between several modules: this is a feature. Code that implicitly modifies variables used far away is confusing and unmaintainable. The real solution is to encapsulate all state within a class and pass its instance to anything that has to modify it. This can make code clearer, more maintainable, more testable, more modular, and more expendable. | 2 | 2 | 0 | I investigated that scope of global variables in python is limited to the module. But I need the scope to be global among different modules. Is there such a thing? I played around __builtin__ but no luck.
thanks in advance! | how to have global variables among different modules in Python | 0.197375 | 0 | 0 | 3,316 |
2,296,550 | 2010-02-19T13:28:00.000 | 0 | 0 | 1 | 0 | python,scope,global-variables | 2,296,580 | 3 | false | 0 | 0 | Scopes beyond the local must be written to via a reference to the scope, or after a global or nonlocal (3.x+) directive. | 2 | 2 | 0 | I investigated that scope of global variables in python is limited to the module. But I need the scope to be global among different modules. Is there such a thing? I played around __builtin__ but no luck.
thanks in advance! | how to have global variables among different modules in Python | 0 | 0 | 0 | 3,316 |
2,297,889 | 2010-02-19T16:31:00.000 | 1 | 1 | 1 | 0 | python,ruby,scripting,dsl,trading | 2,297,992 | 11 | false | 0 | 0 | Custom-made modules are going to be needed, no matter what you choose, that define your firm's high level constructs.
Here are some of the needs I envision -- you may have some of these covered already: a way to get current positions, current and historical quotes, previous performance data, etc... into the application. Define/backtest/send various kinds of orders (limit/market/stop, what exchange, triggers) or parameters of options, etc... You probably are going to need multiple sandboxes for testing as well as the real thing.
Quants want to be able to do matrix operations, stochastic calculus, PDEs.
If you wanted to do it in python, loading NumPy would be a start.
You could also start with a proprietary system designed to do mathematical financial research such as something built on top of Mathematica or Matlab. | 5 | 14 | 0 | I'm currently working on a component of a trading product that will allow a quant or strategy developer to write their own custom strategies. I obviously can't have them write these strategies in natively compiled languages (or even a language that compiles to a bytecode to run on a vm) since their dev/test cycles have to be on the order of minutes.
I've looked at lua, python, ruby so far and really enjoyed all of them so far, but still found them a little "low level" for my target users. Would I need to somehow write my own parser + interpreter to support a language with a minimum of support for looping, simple arithmatic, logical expression evaluation, or is there another recommendation any of you may have? Thanks in advance. | Scripting language for trading strategy development | 0.01818 | 0 | 0 | 3,358 |
2,297,889 | 2010-02-19T16:31:00.000 | 0 | 1 | 1 | 0 | python,ruby,scripting,dsl,trading | 2,298,038 | 11 | false | 0 | 0 | Existing languages are "a little "low level" for my target users."
Yet, all you need is "a minimum of support for looping, simple arithmatic, logical expression evaluation"
I don't get the problem. You only want a few features. What's wrong with the list of languages you provided? They actually offer those features?
What's the disconnect? Feel free to update your question to expand on what the problem is. | 5 | 14 | 0 | I'm currently working on a component of a trading product that will allow a quant or strategy developer to write their own custom strategies. I obviously can't have them write these strategies in natively compiled languages (or even a language that compiles to a bytecode to run on a vm) since their dev/test cycles have to be on the order of minutes.
I've looked at lua, python, ruby so far and really enjoyed all of them so far, but still found them a little "low level" for my target users. Would I need to somehow write my own parser + interpreter to support a language with a minimum of support for looping, simple arithmatic, logical expression evaluation, or is there another recommendation any of you may have? Thanks in advance. | Scripting language for trading strategy development | 0 | 0 | 0 | 3,358 |
2,297,889 | 2010-02-19T16:31:00.000 | 0 | 1 | 1 | 0 | python,ruby,scripting,dsl,trading | 2,298,183 | 11 | false | 0 | 0 | I would use Common Lisp, which supports rapid development (you have a running image and can compile/recompile individual functions) and tailoring the language to your domain. You would provide functions and macros as building blocks to express strategies, and the whole language would be available to the user for combining these. | 5 | 14 | 0 | I'm currently working on a component of a trading product that will allow a quant or strategy developer to write their own custom strategies. I obviously can't have them write these strategies in natively compiled languages (or even a language that compiles to a bytecode to run on a vm) since their dev/test cycles have to be on the order of minutes.
I've looked at lua, python, ruby so far and really enjoyed all of them so far, but still found them a little "low level" for my target users. Would I need to somehow write my own parser + interpreter to support a language with a minimum of support for looping, simple arithmatic, logical expression evaluation, or is there another recommendation any of you may have? Thanks in advance. | Scripting language for trading strategy development | 0 | 0 | 0 | 3,358 |
2,297,889 | 2010-02-19T16:31:00.000 | 0 | 1 | 1 | 0 | python,ruby,scripting,dsl,trading | 2,298,573 | 11 | false | 0 | 0 | Define the language first -- if possible, use the pseudo-language called EBN, it's very simple (see the Wikipedia entry).
Then once you have that, pick the language. Almost certainly you will want to use a DSL. Ruby and Lua are both really good at that, IMO.
Once you start working on it, you may find that you go back to your definition and tweak it. But that's the right order to do things, I think. | 5 | 14 | 0 | I'm currently working on a component of a trading product that will allow a quant or strategy developer to write their own custom strategies. I obviously can't have them write these strategies in natively compiled languages (or even a language that compiles to a bytecode to run on a vm) since their dev/test cycles have to be on the order of minutes.
I've looked at lua, python, ruby so far and really enjoyed all of them so far, but still found them a little "low level" for my target users. Would I need to somehow write my own parser + interpreter to support a language with a minimum of support for looping, simple arithmatic, logical expression evaluation, or is there another recommendation any of you may have? Thanks in advance. | Scripting language for trading strategy development | 0 | 0 | 0 | 3,358 |
2,297,889 | 2010-02-19T16:31:00.000 | 0 | 1 | 1 | 0 | python,ruby,scripting,dsl,trading | 2,298,008 | 11 | false | 0 | 0 | This might be a bit simplistic, but a lot of quant users are used to working with Excel & VBA macros. Would something like VBSCript be usable, as they may have some experience in this area. | 5 | 14 | 0 | I'm currently working on a component of a trading product that will allow a quant or strategy developer to write their own custom strategies. I obviously can't have them write these strategies in natively compiled languages (or even a language that compiles to a bytecode to run on a vm) since their dev/test cycles have to be on the order of minutes.
I've looked at lua, python, ruby so far and really enjoyed all of them so far, but still found them a little "low level" for my target users. Would I need to somehow write my own parser + interpreter to support a language with a minimum of support for looping, simple arithmatic, logical expression evaluation, or is there another recommendation any of you may have? Thanks in advance. | Scripting language for trading strategy development | 0 | 0 | 0 | 3,358 |
2,299,454 | 2010-02-19T20:51:00.000 | 0 | 0 | 1 | 0 | python,dictionary,csv,large-files | 3,279,041 | 6 | false | 0 | 0 | my idea is to use python zodb module to store dictionaty type data and then create new csv file using that data structure. do all your operation at that time. | 2 | 4 | 1 | I'm reading a 6 million entry .csv file with Python, and I want to be able to search through this file for a particular entry.
Are there any tricks to search the entire file? Should you read the whole thing into a dictionary or should you perform a search every time? I tried loading it into a dictionary but that took ages so I'm currently searching through the whole file every time which seems wasteful.
Could I possibly utilize that the list is alphabetically ordered? (e.g. if the search word starts with "b" I only search from the line that includes the first word beginning with "b" to the line that includes the last word beginning with "b")
I'm using import csv.
(a side question: it is possible to make csv go to a specific line in the file? I want to make the program start at a random line)
Edit: I already have a copy of the list as an .sql file as well, how could I implement that into Python? | How do quickly search through a .csv file in Python | 0 | 0 | 0 | 20,439 |
2,299,454 | 2010-02-19T20:51:00.000 | 1 | 0 | 1 | 0 | python,dictionary,csv,large-files | 2,443,606 | 6 | false | 0 | 0 | You can't go directly to a specific line in the file because lines are variable-length, so the only way to know when line #n starts is to search for the first n newlines. And it's not enough to just look for '\n' characters because CSV allows newlines in table cells, so you really do have to parse the file anyway. | 2 | 4 | 1 | I'm reading a 6 million entry .csv file with Python, and I want to be able to search through this file for a particular entry.
Are there any tricks to search the entire file? Should you read the whole thing into a dictionary or should you perform a search every time? I tried loading it into a dictionary but that took ages so I'm currently searching through the whole file every time which seems wasteful.
Could I possibly utilize that the list is alphabetically ordered? (e.g. if the search word starts with "b" I only search from the line that includes the first word beginning with "b" to the line that includes the last word beginning with "b")
I'm using import csv.
(a side question: it is possible to make csv go to a specific line in the file? I want to make the program start at a random line)
Edit: I already have a copy of the list as an .sql file as well, how could I implement that into Python? | How do quickly search through a .csv file in Python | 0.033321 | 0 | 0 | 20,439 |
2,299,627 | 2010-02-19T21:15:00.000 | 0 | 1 | 0 | 1 | python,windows,wmi | 2,505,040 | 2 | false | 0 | 0 | Process name: is sys.argv[0] not sufficient for your purposes? | 1 | 0 | 0 | What is the best way in python find the process name and owner?
Now i use WMI, but this version is too slow. | python and process | 0 | 0 | 0 | 325 |
2,299,697 | 2010-02-19T21:23:00.000 | 1 | 0 | 0 | 0 | python,django,django-models,wiki | 2,299,776 | 3 | false | 1 | 0 | Assuming that there will be a community of users you can provide good tools for them to spot problems and easily undo damage. The most important of these is to provide a Recent Changes page that summarizes recent edits. Then each page that can be edited should retain prior versions of the page that can be used to replace any damaging edit. This makes it easier to undo damage than it is to damage things.
Then think about how you are going to handle either locking resources or handling simultaneous edits.
If you can tie edits to users you can provide some administrative functions for undoing all edits by a particular user, and banning that user.
Checking for quality would be tied to the particular data that your application is using. | 2 | 0 | 0 | I'm building this app in Python with Django.
I would like to give parts of the site wiki like functionality,
but I don't know how to go on about reliability and security.
Make sure that good content is not ruined
Check for quality
Prevent spam from invading the site
The items requiring wiki like functionality are just a few: a couple of text fields.
Can anyone help on this one?
Would be very much appreciated. :) | Building a wiki application? | 0.066568 | 0 | 0 | 1,412 |
2,299,697 | 2010-02-19T21:23:00.000 | 1 | 0 | 0 | 0 | python,django,django-models,wiki | 2,299,849 | 3 | false | 1 | 0 | Make sure that good content is not ruined = version each edit and allow roll-backs.
Check for quality = get people to help with that
Prevent spam from invading the site = get people to help with that, require login, add a captcha if need be, use nofollow for all links | 2 | 0 | 0 | I'm building this app in Python with Django.
I would like to give parts of the site wiki like functionality,
but I don't know how to go on about reliability and security.
Make sure that good content is not ruined
Check for quality
Prevent spam from invading the site
The items requiring wiki like functionality are just a few: a couple of text fields.
Can anyone help on this one?
Would be very much appreciated. :) | Building a wiki application? | 0.066568 | 0 | 0 | 1,412 |
2,299,751 | 2010-02-19T21:32:00.000 | 0 | 0 | 0 | 0 | python,ping,icmp | 2,299,927 | 1 | true | 0 | 0 | A problem you might be having is due to the fact that ICMP is layer 3 of the OSI model and does not use a port for communication. In short, ICMP isn't really designed for this. The desired behavior is still possible but perhaps the IP Stack you are using is getting in the way and if this is on a Windows system then 100% sure this is your problem. I would fire up Wireshark to make sure you are actually getting incoming packets, if this is the case then I would use libpcap to track in ICMP replies. If the problem is with sending then you'll have to use raw sockets and build your own ICMP packets. | 1 | 1 | 0 | I'm writing service in python that async ping domains. So it must be able to ping many ip's at the same time. I wrote it on epoll ioloop, but have problem with packets loss.
When there are many simultaneous ICMP requests much part of replies on them didn't reach my servise. What may cause this situation and how i can make my service ping many hosts at the same time without packet loss?
Thanks) | Problem with asyn icmp ping | 1.2 | 0 | 1 | 788 |
2,301,458 | 2010-02-20T07:38:00.000 | 8 | 0 | 1 | 0 | python,file,multithreading | 2,301,462 | 3 | false | 0 | 0 | When two threads access the same resources, weird things happen. To avoid that, always lock the resource. Python has the convenient threading.Lock for that, as well as some other tools (see documentation of the threading module). | 1 | 14 | 0 | I have two threads, one which writes to a file, and another which periodically
moves the file to a different location. The writes always calls open before writing a message, and calls close after writing the message. The mover uses shutil.move to do the move.
I see that after the first move is done, the writer cannot write to the file anymore, i.e. the size of the file is always 0 after the first move. Am I doing something wrong? | Python multiple threads accessing same file | 1 | 0 | 0 | 28,811 |
2,302,663 | 2010-02-20T15:32:00.000 | 3 | 0 | 1 | 0 | python,parameter-passing | 2,302,668 | 3 | false | 0 | 0 | Dictionaries don't preserve the order of the keys. You could use a list of tuples instead of a dictionary. | 1 | 1 | 0 | def createNode(doc_, **param_):
cache = {'p':'property','l':'label','td':'totalDelay','rd':'routeDelay','ld':'logicDelay'}
for index in param_:
newIndex = cache[index]
value = param_[index]
print newIndex, '=', value
doc = 10
createNode(doc, p='path', l='ifft4k_radix4_noUnolling_core.vi', td='3.0', ld='1.0', rd='2.0')
Running this code on Python 2.6 gives me the following result.
routeDelay = 2.0
property = path
totalDelay = 3.0
logicDelay = 1.0
label = ifft4k_radix4_noUnolling_core.vi
I need to keep the order of the parameters, I mean, property comes first, then label until I get routeDelay last.
Q : What's the way to keep the dictionary parameter order in Python? | What's the way to keep the dictionary parameter order in Python? | 0.197375 | 0 | 0 | 2,708 |
2,302,761 | 2010-02-20T16:05:00.000 | 0 | 0 | 0 | 0 | java,python,sockets | 2,302,787 | 2 | false | 0 | 0 | Typically when doing client-server communication you need to establish some kind of protocol. One very simple protocol is to send the String "COMMAND" before you send any commands and the String "ERROR" before you send any errors. This doubles the number of Strings you have to send but gives more flexibility.
There are also a number of more sophisticated protocols already developed. Rather than sending Strings you could construct a Request object which you then serialize and send to the client. The client can then reconstruct the Request object and perform the request whether it's performing an error or running a command. | 2 | 1 | 0 | I am writing a general Client-Server socket program where the client sends commands to the Server, which executes it and sends the result to the Client.
However if there is an error while executing a command, I want to be able to inform the Client of an error. I know I could send the String "ERROR" or maybe something like -1 etc, but these could also be part of the command output. Is there any better way of sending an error or an exception over a socket.
My Server is in Java and Client is in Python | Pass error on socket | 0 | 0 | 1 | 134 |
2,302,761 | 2010-02-20T16:05:00.000 | 0 | 0 | 0 | 0 | java,python,sockets | 2,302,805 | 2 | false | 0 | 0 | You're already (necessarily) establishing some format or protocol whereby strings are being sent back and forth -- either you're somehow terminating each string, or sending its length first, or the like. (TCP is intrinsically just a stream so without such a protocol there would be no way the recipient could possibly know when the command or output is finished!-)
So, whatever approach you're using to delimiting strings, just make it so the results sent back from server to client are two strings each and every time: one being the error description (empty if no error), the other being the commands's results (empty if no results). That's going to be trivial both to send and receive/parse, and have minimal overhead (sending an empty string should be as simple as sending just a terminator or a length of 0). | 2 | 1 | 0 | I am writing a general Client-Server socket program where the client sends commands to the Server, which executes it and sends the result to the Client.
However if there is an error while executing a command, I want to be able to inform the Client of an error. I know I could send the String "ERROR" or maybe something like -1 etc, but these could also be part of the command output. Is there any better way of sending an error or an exception over a socket.
My Server is in Java and Client is in Python | Pass error on socket | 0 | 0 | 1 | 134 |
2,303,254 | 2010-02-20T18:53:00.000 | 2 | 0 | 0 | 0 | python,django | 8,542,155 | 3 | false | 1 | 0 | When you creates a model with ImageField or FileField attributes, you should pass the upload_to argument. That is a relative path will be appended to your MEDIA_ROOT path and there will be save and retrieve that files. | 1 | 9 | 0 | What does Django do with MEDIA_ROOT exactly? I never understood it. Since Django itself doesn't serve static media, and you have to set up apache or something similar for it, why does it care in which directory it sits? | What does Django do with `MEDIA_ROOT`? | 0.132549 | 0 | 0 | 4,138 |
2,303,683 | 2010-02-20T20:55:00.000 | 2 | 1 | 1 | 0 | python,c,performance,bytecode | 2,303,703 | 4 | false | 0 | 1 | It makes sense to use C modules in Python for:
Performance
Libraries that won't be ported to Python (because of performance reasons, for example) or that use OS-specific functions
Scripting. For example, many games use Python, Lua and other languages as scripting languages. Therefore they expose C/C++ functions to Python.
As to your example: Yes, but Python is inherently slower than C. If both were equally fast, it would make sense to use Python because C code is often more prone to attacks (buffer overflows and stuff). | 3 | 1 | 0 | If Python was so fast as C, the latter would be present in python apps/libraries?
Example: if Python was fast as C would PIL be written completely in Python? | Is there any purpose for a python application use C other than performance? | 0.099668 | 0 | 0 | 196 |
2,303,683 | 2010-02-20T20:55:00.000 | 0 | 1 | 1 | 0 | python,c,performance,bytecode | 2,303,876 | 4 | false | 0 | 1 | To access hardware. | 3 | 1 | 0 | If Python was so fast as C, the latter would be present in python apps/libraries?
Example: if Python was fast as C would PIL be written completely in Python? | Is there any purpose for a python application use C other than performance? | 0 | 0 | 0 | 196 |
2,303,683 | 2010-02-20T20:55:00.000 | 7 | 1 | 1 | 0 | python,c,performance,bytecode | 2,303,685 | 4 | true | 0 | 1 | To access "legacy" C libraries and OS facilities. | 3 | 1 | 0 | If Python was so fast as C, the latter would be present in python apps/libraries?
Example: if Python was fast as C would PIL be written completely in Python? | Is there any purpose for a python application use C other than performance? | 1.2 | 0 | 0 | 196 |
2,303,956 | 2010-02-20T22:12:00.000 | 8 | 0 | 0 | 1 | python,emacs,virtualenv | 2,307,435 | 2 | true | 0 | 0 | So it seems that python-shell does the right thing by picking up the environment settings, whereas py-shell does not. python-shell is provided by python.el and py-shell is provided by python-mode.el , There's bug reports etc related to this, so I'm just not going to use py-shell for now. Figured I'd close the loop on this in case the google machine considers this a high ranking item for one reason or another. | 1 | 12 | 0 | Today I've been trying to bring more of the Python related modes into
my Emacs configuration but I haven't had much luck.
First what I've noticed is that depending on how Emacs is
launched (terminal vs from the desktop), the interpreter it decides to
use is different.
launched from KDE menu: M-! which python gives /usr/bin/python
launched from terminal: M-! which python gives ~/local/bin/python
I can kind of accept this since I have my .bashrc appending
~/local/bin to the path and I guess KDE ignores that by default. I can
work around this, however what I don't understand is then if I
activate a virtualenv, I would expect M-! which python to point to
~/project.env/bin/python however it still points to ~/local/bin/python.
Thus when I M-x py-shell, I get ~/local/bin/python so if I try to
M-x py-execute-buffer on a module that resides in a package in the
virtualenv, py-shell will complain about not knowing about modules
also in the virtualenv.
Setting py-python-command to "~/project.env/bin/python" seems to have no
effect after everything is loaded.
So I guess the overall crux of my question is, how does one get all
the python related emacs stuff pointing at the right interpreter? | Specifying python interpreter from virtualenv in emacs | 1.2 | 0 | 0 | 6,786 |
2,303,966 | 2010-02-20T22:17:00.000 | -2 | 0 | 0 | 0 | python,django,geolocation | 2,303,976 | 2 | true | 1 | 0 | You can't collect a real zip code from an IP address as these are assigned by ISP's when you route threw their connection. | 1 | 3 | 0 | Is it possible to find the zip code based on a users IP address using python / django (not geodjango)? I assume I would have to use a web service, but I would really like to just be able to query a database if possible.
I am using geopy right now, so it would be cool if I could integrate that somehow. | Get zip code based on IP Address with Python | 1.2 | 0 | 0 | 3,231 |
2,304,632 | 2010-02-21T03:19:00.000 | 2 | 1 | 1 | 0 | python,regex,twitter | 2,304,704 | 11 | false | 0 | 0 | The only characters accepted in the form are A-Z, 0-9, and underscore. Usernames are not case-sensitive, though, so you could use r'@(?i)[a-z0-9_]+' to match everything correctly and also discern between users. | 2 | 46 | 0 | Could you provide a regex that match Twitter usernames?
Extra bonus if a Python example is provided. | regex for Twitter username | 0.036348 | 0 | 0 | 35,359 |
2,304,632 | 2010-02-21T03:19:00.000 | 1 | 1 | 1 | 0 | python,regex,twitter | 2,330,440 | 11 | false | 0 | 0 | Shorter, /@([\w]+)/ works fine. | 2 | 46 | 0 | Could you provide a regex that match Twitter usernames?
Extra bonus if a Python example is provided. | regex for Twitter username | 0.01818 | 0 | 0 | 35,359 |
2,305,115 | 2010-02-21T06:49:00.000 | 2 | 0 | 1 | 0 | python,file-io | 2,305,125 | 6 | false | 0 | 0 | Open a second file to write to, read and then write the lines you want to copy over, write the new lines, read the lines you want to skip, then copy the rest. | 1 | 4 | 0 | I have a text file looks like:
first line
second line
third line
forth line
fifth line
sixth line
I want to replace the third and forth lines with three new lines. The above contents would become:
first line
second line
new line1
new line2
new line3
fifth line
sixth line
How can I do this using Python? | Remove and insert lines in a text file | 0.066568 | 0 | 0 | 15,256 |
2,305,353 | 2010-02-21T08:48:00.000 | 1 | 0 | 0 | 0 | python,sql,django,security,sql-injection | 2,305,359 | 2 | false | 1 | 0 | Create and use non-modifiable views. | 2 | 2 | 0 | I'm planning on building a Django log-viewing app with powerful filters. I'd like to enable the user to finely filter the results with some custom (possibly DB-specific) SELECT queries.
However, I dislike giving the user write access to the database. Is there a way to make sure a query doesn't change anything in the database? Like a 'dry run' flag? Or is there a way to filter SELECT queries so that they can't be harmful in any way?
I thought about running the queries as a separate MySQL user but I'd rather avoid the hassle. I also thought about using Google App Engine's GQL 'language', but if there is a cleaner solution, I'd certainly like to hear it :)
Thanks. | How can I limit an SQL query to be nondestructive? | 0.099668 | 1 | 0 | 543 |
2,305,353 | 2010-02-21T08:48:00.000 | 14 | 0 | 0 | 0 | python,sql,django,security,sql-injection | 2,305,379 | 2 | true | 1 | 0 | Connect with a user that has only been granted SELECT permissions. Situations like this is why permissions exist in the first place. | 2 | 2 | 0 | I'm planning on building a Django log-viewing app with powerful filters. I'd like to enable the user to finely filter the results with some custom (possibly DB-specific) SELECT queries.
However, I dislike giving the user write access to the database. Is there a way to make sure a query doesn't change anything in the database? Like a 'dry run' flag? Or is there a way to filter SELECT queries so that they can't be harmful in any way?
I thought about running the queries as a separate MySQL user but I'd rather avoid the hassle. I also thought about using Google App Engine's GQL 'language', but if there is a cleaner solution, I'd certainly like to hear it :)
Thanks. | How can I limit an SQL query to be nondestructive? | 1.2 | 1 | 0 | 543 |
2,305,501 | 2010-02-21T09:52:00.000 | 2 | 0 | 1 | 0 | python,dictionary,sampling | 2,305,591 | 4 | false | 0 | 0 | If the values are too large for gnibler's approach:
Build a list of tuples (key, index), where index is the sum of all values that come before key in the list (this would be the index of the first occurrence of key gnibler's list c. Also calculate the sum of all values (n).
Now, generate a random number xbetween 0 and n - 1. Find the last entry in the list with index < x. Since the list is sorted by index, you can use binary search to do that efficiently.
Update: KennyTM's code is an implementation of this, except that he uses a brute-force linear search instead of binary search; this will be inefficient if the number of keys are large. | 1 | 1 | 0 | I have a dictionary in python with key->value as str->int. If I have to chose a key based on it's own value, then as the value gets larger the key has a lower possibility of being chosen.
For example, if key1=2 and key2->1, then the attitude of key1 should be 2:1.
How can I do this? | Sampling keys due to their values | 0.099668 | 0 | 0 | 131 |
2,306,048 | 2010-02-21T13:45:00.000 | 24 | 0 | 0 | 0 | python,mysql,django,sqlite,dev-to-production | 2,306,070 | 6 | true | 1 | 0 | I'd highly recommend using the same database backend in production as in development, and all stages in between. Django will abstract the database stuff, but having different environments will leave you open to horrible internationalisation, configuration issues, and nasty tiny inconsistencies that won't even show up until you push it live.
Personally, I'd stick to mysql, but I never got on with postgres :) | 4 | 20 | 0 | Quick question: is it a good idea to use sqlite while developing a Django project, and use MySQL on the production server? | Django: sqlite for dev, mysql for prod? | 1.2 | 1 | 0 | 4,303 |
2,306,048 | 2010-02-21T13:45:00.000 | 7 | 0 | 0 | 0 | python,mysql,django,sqlite,dev-to-production | 9,401,789 | 6 | false | 1 | 0 | Use the same database in all environments.
As much as the ORM tries to abstract the differences between databases, there will always be certain features that behave differently based on the database. Database portability is a complete myth.
Plus, it seems pretty insane to test and develop against code paths that you will never use in production, doesn't it? | 4 | 20 | 0 | Quick question: is it a good idea to use sqlite while developing a Django project, and use MySQL on the production server? | Django: sqlite for dev, mysql for prod? | 1 | 1 | 0 | 4,303 |
2,306,048 | 2010-02-21T13:45:00.000 | 3 | 0 | 0 | 0 | python,mysql,django,sqlite,dev-to-production | 2,306,069 | 6 | false | 1 | 0 | In short, no; unless you want to unnecessarily double development time. | 4 | 20 | 0 | Quick question: is it a good idea to use sqlite while developing a Django project, and use MySQL on the production server? | Django: sqlite for dev, mysql for prod? | 0.099668 | 1 | 0 | 4,303 |
2,306,048 | 2010-02-21T13:45:00.000 | 3 | 0 | 0 | 0 | python,mysql,django,sqlite,dev-to-production | 12,684,980 | 6 | false | 1 | 0 | Just made this major mistake starting off with sqlite and when i try to deploy on production server with mysql, things didn't work as smooth as i expected. I tried dumpdata/loaddata with various switches but somehow keep getting errors thrown one after another. Do yourself a big favor and use the same db for both production and development. | 4 | 20 | 0 | Quick question: is it a good idea to use sqlite while developing a Django project, and use MySQL on the production server? | Django: sqlite for dev, mysql for prod? | 0.099668 | 1 | 0 | 4,303 |
2,306,984 | 2010-02-21T18:50:00.000 | 1 | 0 | 0 | 0 | python,oauth,google-api | 3,110,939 | 1 | true | 1 | 0 | When you're exchanging for the access token, the oauth_verifier parameter is required. If you don't provide that parameter, then google will tell you that the token is invalid. | 1 | 2 | 0 | I am having trouble exchanging my Oauth request token for an Access Token. My Python application successfully asks for a Request Token and then redirects to the Google login page asking to grant access to my website. When I grant access I retrieve a 200 status code but exchanging this authorized request token for an access token gives me a 'The token is invalid' message.
The Google Oauth documentation says: "Google redirects with token and verifier regardless of whether the token has been authorized." so it seems that authorizing the request token fails but then I am not sure how I should get an authorized request token. Any suggestions? | Exchange Oauth Request Token for Access Token fails Google API | 1.2 | 0 | 1 | 1,332 |
2,307,464 | 2010-02-21T21:09:00.000 | 30 | 0 | 0 | 0 | python,tkinter | 42,928,131 | 4 | false | 0 | 1 | root.quit() causes mainloop to exit. The interpreter is still intact, as are all the widgets. If you call this function, you can have code that executes after the call to root.mainloop(), and that code can interact with the widgets (for example, get a value from an entry widget).
Calling root.destroy() will destroy all the widgets and exit mainloop. Any code after the call to root.mainloop() will run, but any attempt to access any widgets (for example, get a value from an entry widget) will fail because the widget no longer exists. | 2 | 39 | 0 | In Python using tkinter, what is the difference between root.destroy() and root.quit() when closing the root window?
Is one prefered over the other? Does one release resources that the other doesn't? | What is the difference between root.destroy() and root.quit()? | 1 | 0 | 0 | 35,380 |
2,307,464 | 2010-02-21T21:09:00.000 | 0 | 0 | 0 | 0 | python,tkinter | 61,423,826 | 4 | false | 0 | 1 | My experience with root.quit() and root.destroy() ...
I have a dos python script, which calls a tkinter script (to choose from set of known values from combobox), then returns to the dos script to complete other things.
The TKinter script I've added onto the parent script. I may convert all to tkinter, but a combo works for the time being. It works in the following way:
To get rid of the windows box after selection was implemented, I needed to
1) root.quit() inside the callback function where all my keypresses were being processed.
2) root.destroy() after mainloop to destroy the windows box.
If I used root.destroy() inside the callback, I got an error message saying tkinter objects were no longer accessable.
Without the root.destroy() after mainloop, the windows box STAYED ONSCREEN until the whole parent script had completed. | 2 | 39 | 0 | In Python using tkinter, what is the difference between root.destroy() and root.quit() when closing the root window?
Is one prefered over the other? Does one release resources that the other doesn't? | What is the difference between root.destroy() and root.quit()? | 0 | 0 | 0 | 35,380 |
2,308,050 | 2010-02-22T00:05:00.000 | 0 | 0 | 0 | 1 | python,google-app-engine,task-queue | 2,402,964 | 1 | false | 1 | 0 | When a task-queue ends in error : I believe it stays in your queue ..
Check that | 1 | 2 | 0 | I have been testing the taskqueue with mixed success. Currently I am
using the default queue, in default settings etc etc....
I have a test URL setup which inserts about 8 tasks into the queue.
With short order, all 8 are completed properly. So far so good.
The problem comes up when I re-load that URL twice under say a minute.
Now watching the task queue, all the tasks are added properly, but
only the first batch execute it seems. But the "Run in Last Minute" #
shows the right number of tasks being run....
The request logs tell a different story. They show only the first set
of 8 running, but all task creation URLs working successfully.
The oddness of this is that if I wait say a minute between the task
creation URL requests, it will work fine.
Oddly enough changing the bucket_size or execution speed does not seem
to help. Only the first batch are executed. I have also reduced the
number of requests all the way down to 2, and still found only the
first 2 execute. Any others added display the same issues as above.
Any suggestions?
Thanks | GAE Task Queue oddness | 0 | 0 | 0 | 630 |
2,308,443 | 2010-02-22T02:20:00.000 | 9 | 0 | 1 | 0 | python | 2,308,452 | 4 | true | 0 | 0 | It really depends where you get your number from.
If the number you are trying to convert comes from user input, use locale.atoi(). That way, the number will be parsed in a way that is consistent with the user's settings and thus expectations.
If on the other hand you read it, let's say, from a file, that always uses the same format, use int("1,234".replace(",", "")) or int("1.234".replace(".", "")) depending on your situation. This is not only easier to read and debug, but it's not affected by the user's locale setting, so your parser will work on any system. | 1 | 7 | 0 | In Python, what is a clean and elegant way to convert strings like "1,374" or "21,000,000" to int values like 1374 or 21000000? | How to convert a numeric string with place-value commas into an integer? | 1.2 | 0 | 0 | 4,118 |
2,309,108 | 2010-02-22T06:02:00.000 | 0 | 1 | 1 | 0 | python,mobile-phones,imei | 2,309,202 | 1 | false | 0 | 0 | Sending AT+CGSN through the appropriate serial device will have it return the IMEI. | 1 | 0 | 0 | How can I get the IMEI number of a mobile phone using Python? | IMEI number of a mobile phone using python | 0 | 0 | 0 | 2,251 |
2,309,645 | 2010-02-22T08:26:00.000 | 2 | 0 | 1 | 0 | python,function,arguments,argument-passing | 2,309,739 | 4 | false | 0 | 0 | I see that someone has already offered the answer i had in mind, so i'll suggest a purely practical one. IDLE will give you a function's parameters as a 'tooltip'.
This should be enabled by default; the tooltip will appear just after you type the function name and the left parenthesis.
To do this, IDLE just accesses the function's doc string, so it will show the tooltip for any python function--standard library, third-party library, or even a function you've created earlier and is in a namespace accessible to IDLE.
Obviously, this is works only when you are working in interactive mode in IDLE, though it does have the advantage of not requiring an additional function call. | 2 | 3 | 0 | Suppose I have a function and I want to print out the arguments it accepts. How can I do this? | How do I print out which arguments a Python function requires/allows? | 0.099668 | 0 | 0 | 357 |
2,309,645 | 2010-02-22T08:26:00.000 | 0 | 0 | 1 | 0 | python,function,arguments,argument-passing | 2,310,447 | 4 | false | 0 | 0 | The help function does this.
All you have to do is put in docstrings for your functions. | 2 | 3 | 0 | Suppose I have a function and I want to print out the arguments it accepts. How can I do this? | How do I print out which arguments a Python function requires/allows? | 0 | 0 | 0 | 357 |
2,310,130 | 2010-02-22T10:11:00.000 | 2 | 0 | 1 | 0 | python,user-interface | 2,310,200 | 6 | false | 0 | 1 | As an answer for #1: Yes. It is quite good for this; scripting languages with GUI toolkits are often a good way to put a GUI on an application. They can also be used to wrap applications written in low level languages such as C or C++. Python offers good integration to quite a few toolkits. The posting linked above gives a pretty good cross section of the options with code samples.
For #2: TkInter comes with the standard distribution. It is easy to use but not as sophisticated as (say) QT or WxWidgets. | 1 | 11 | 0 | I would like to try to write a GUI application in Python. I found out that there are a lot of ways to do it (different toolkits). And, in this context, I have several basic (and I think simple) question?
Is it, in general, a good idea to write a GUI application in Python?
What is the standard (easiest and most stable) way to create a GUI applications in Python?
Does anybody can give me a link to a simple Hello World GUI application written in Python? | How to write GUI in Python? | 0.066568 | 0 | 0 | 20,880 |
2,311,074 | 2010-02-22T13:22:00.000 | 0 | 0 | 1 | 1 | python,windows,command-line,command-prompt | 2,311,082 | 3 | false | 0 | 0 | Is python.exe in your windows path? Try to look at the PATH environment variable and see if the installation folder of python is listed there. | 2 | 2 | 0 | I have just installed Python on my Windows 7. I thought that after that I will be able to run python on the command prompt but it is not the case. After the installation I also found out that I can run the python command shell. This is nice. But what should I do if I want to save my program in a file and then I want to run this program (in Linux, for example, I typed "python file_name.py" in the command line). | How can I get python in the command prompt on Windows? | 0 | 0 | 0 | 314 |
2,311,074 | 2010-02-22T13:22:00.000 | 0 | 0 | 1 | 1 | python,windows,command-line,command-prompt | 2,311,098 | 3 | false | 0 | 0 | You need to update your environment variables to include the path to the Python executable.
On XP you can do this by right clicking on "My Computer" -> Properties and then going to the "Advanced" tab. | 2 | 2 | 0 | I have just installed Python on my Windows 7. I thought that after that I will be able to run python on the command prompt but it is not the case. After the installation I also found out that I can run the python command shell. This is nice. But what should I do if I want to save my program in a file and then I want to run this program (in Linux, for example, I typed "python file_name.py" in the command line). | How can I get python in the command prompt on Windows? | 0 | 0 | 0 | 314 |
2,311,094 | 2010-02-22T13:27:00.000 | 0 | 0 | 0 | 0 | python,django,user-management | 2,311,740 | 2 | false | 1 | 0 | If I'm understanding you correctly, it seems like you want to have two different groups have access to all the same views, but they will see different numbers. You can achieve this effect by making separate templates for the different groups, and then loading the appropriate template for each view depending on the group of the current user.
Similarly you can use a context processor to put the current group into the context for every view, and then put conditionals in the templates to select which numbers to show.
The other option is to have two separate sets of views for the two different groups. Then use decorators on the views to make sure the groups only go to the views that are for them. | 1 | 2 | 0 | Background information:
I have created an internal site for a company. Most of the work has gone into making calculation tools that their sale persons can use to make offers for clients. Create pdf offers and contracts that can be downloaded, compare prices etc. All of this is working fine.
Now their sale persons have been divided into two groups.
One group is sale personal that is hired by the company.
The other group is persons a company themselves.
The question:
My challenge now is, that I in some cases need to display different things depending on the type of sales person. Some of the rules for the calculation tools will have different rules as to which numbers will be allowed etc. But a big part of the site will still be the same for both groups.
What I would like to know, is if there is a good way of handling this problem?
My own thoughts:
I thought about managing this by using the groups that is available in contrib.auth. That way I could keep a single code base, but would have to make rules a lot of different places. Rules for validating forms to check if the numbers entered is allowed, will depend on the group the user is in. Some things will have different names, or the workflow might be a bit different. Some tools will only be available to one of the groups. This seems like a quick solution here and now, but if the two groups will need to change more and more, it seems like this would quickly become hard to manage.
I also thought about making two different sites. The idea here was to create apps that both groups use, so I only would need to make the code for that 1 place. Then I could make the custom parts for each site and wouldn't need to check for the user in most templates and views. But I'm not sure if this is a good way to go about things. It will create a lot of extra work, and if the two groups can use a lot of the same code, this might not really be needed.
The biggest concern is that I don't really know how this evolve, so it could end up with the two groups being entire different or with only very few differences. What I would like to do, is write some code that can support both scenarios so I wont end up regretting my choice a half year from now.
So, how do you handle this case of user management. I'm looking for ideas techniques or reusable apps that address this problem, not a ready made solution.
Clarifications:
My issue is not pure presentation that can be done with templates, but also that certain calculation tools (a form that is filled out) will have different rules/validation applied to them, and in some cases the calculations done will also be different. So they might see the same form, but wont be allowed to enter the same numbers, and the same numbers might not give the same result. | How to handle user mangement in Django for groups that has same access but different rules? | 0 | 0 | 0 | 439 |
2,311,102 | 2010-02-22T13:28:00.000 | 0 | 0 | 1 | 0 | python,configparser | 2,311,146 | 3 | false | 0 | 0 | Doesn't RawConfigParser.has_option(section, option) do the job? | 1 | 3 | 0 | I have a config file that I read using the RawConfigParser in the standard ConfigParser library. My config file has a [DEFAULT] section followed by a [specific] section. When I loop through the options in the [specific] section, it includes the ones under [DEFAULT], which is what is meant to happen.
However, for reporting I wanted to know whether the option had been set in the [specific] section or in [DEFAULT]. Is there any way of doing that with the interface of RawConfigParser, or do I have no option but to parse the file manually? (I have looked for a bit and I'm starting to fear the worst ...)
For example
[DEFAULT]
name = a
surname = b
[SECTION]
name = b
age = 23
How do you know, using RawConfigParser interface, whether options name & surname are loaded from section [DEFAULT] or section [SECTION]?
(I know that [DEFAULT] is meant to apply to all, but you may want to report things like this internally in order to work your way through complex config files)
thanks! | Python ConfigParser: how to work out options set in a specific section (rather than defaults) | 0 | 0 | 0 | 7,751 |
2,311,223 | 2010-02-22T13:49:00.000 | 2 | 0 | 1 | 0 | python,database,string,list,dictionary | 2,312,727 | 5 | false | 0 | 0 | There are any number of serialization methods out there, JSON is readable, reasonably compact, supported natively, and portable. I prefer it over pickle, since the latter can execute arbitrary code and potentially introduce security holes, and because of its portability.
Depending on your data's layout, you may also be able to use your ORM to directly map the data into database constructs. | 3 | 1 | 0 | If I have a dictionary full of nested stuff, how do I store that in a database, as a string? and then, convert it back to a dictionary when I'm ready to parse?
Edit: I just want to convert it to a string...and then back to a dictionary. | How do I store a dict/list in a database? | 0.07983 | 0 | 0 | 2,541 |
2,311,223 | 2010-02-22T13:49:00.000 | 4 | 0 | 1 | 0 | python,database,string,list,dictionary | 2,311,245 | 5 | false | 0 | 0 | Options:
1) Pickling
2) XML
3) JSON
others I am sure. It has a lot to do on how much portability means to you. | 3 | 1 | 0 | If I have a dictionary full of nested stuff, how do I store that in a database, as a string? and then, convert it back to a dictionary when I'm ready to parse?
Edit: I just want to convert it to a string...and then back to a dictionary. | How do I store a dict/list in a database? | 0.158649 | 0 | 0 | 2,541 |
2,311,223 | 2010-02-22T13:49:00.000 | 1 | 0 | 1 | 0 | python,database,string,list,dictionary | 2,312,726 | 5 | false | 0 | 0 | You have two options
use a standard serialization format (json, xml, yaml, ...)
pros: you can access with a any language that can parse those formats (on the worst case you can write your own parser)
cons: could be slower to save and load the data (this depends of the implementation mostly)
use cPickle:
pros: easy to use, fast and native python way to do serialization.
cons: only python based apps can have access to the data. | 3 | 1 | 0 | If I have a dictionary full of nested stuff, how do I store that in a database, as a string? and then, convert it back to a dictionary when I'm ready to parse?
Edit: I just want to convert it to a string...and then back to a dictionary. | How do I store a dict/list in a database? | 0.039979 | 0 | 0 | 2,541 |
2,311,455 | 2010-02-22T14:28:00.000 | 1 | 0 | 1 | 1 | python,command-line,desktop,command-prompt | 2,332,334 | 4 | false | 0 | 0 | Use py2exe to make an exe and just to make it more 'user friendly' use Inno set up (www.jrsoftware.org/isinfo.php ) along with IStools to build up an installer which would integrate the GUI with sound, widgets, other elements etc and users who do not have python etc installed in their systems can also play your GUI perfectly fine !
By the way what GUI are you using ? pygame, tk, wx, PyQt ...etc ? | 1 | 0 | 0 | I have a Python program (GUI application). I can run this program from the command prompt on Windows (command line on Linux). But it can be too complicated for users. Is there an easy way to initiate a start of the program with a click (double click) on a pictogram (a small image on the desktop)? | How to make a user friendly start of a Python program? | 0.049958 | 0 | 0 | 3,714 |
2,312,169 | 2010-02-22T16:06:00.000 | 0 | 0 | 1 | 0 | python,operators | 2,312,204 | 3 | false | 0 | 0 | you shouldn't use <> in python. | 2 | 5 | 0 | I think if I understand correctly, a <> b is the exact same thing functionally as a != b, and in Python not a == b, but is there reason to use <> over the other versions? I know a common mistake for Python newcomers is to think that not a is b is the same as a != b or not a == b.
Do similar misconceptions occur with <>, or is it exactly the same functionally?
Does it cost more in memory, processor, etc. | Python ( or general programming ). Why use <> instead of != and are there risks? | 0 | 0 | 0 | 492 |
2,312,169 | 2010-02-22T16:06:00.000 | 15 | 0 | 1 | 0 | python,operators | 2,312,202 | 3 | true | 0 | 0 | <> in Python 2 is an exact synonym for != -- no reason to use it, no disadvantages either except the gratuitous heterogeneity (a style issue). It's been long discouraged, and has now been removed in Python 3. | 2 | 5 | 0 | I think if I understand correctly, a <> b is the exact same thing functionally as a != b, and in Python not a == b, but is there reason to use <> over the other versions? I know a common mistake for Python newcomers is to think that not a is b is the same as a != b or not a == b.
Do similar misconceptions occur with <>, or is it exactly the same functionally?
Does it cost more in memory, processor, etc. | Python ( or general programming ). Why use <> instead of != and are there risks? | 1.2 | 0 | 0 | 492 |
2,313,017 | 2010-02-22T18:11:00.000 | 0 | 1 | 0 | 1 | java,python,programming-languages,binding,java-native-interface | 2,313,266 | 3 | false | 0 | 0 | I would use Python. You could write very basic wrappers using the Python C API and then call said functions from Python with relative ease. | 3 | 1 | 0 | I have quite a lot of C++ legacy code modules from my colleagues, unfortunately poorly written. Each is doing a different job, but they are all GNU C++ code running under Linux.
I want to write a controller program, to make a singular C++ module for a workflow, for a very urgent demo. Also I need to write a front-end web-app allowing clients submitting jobs to the controller.
My main criteria are:
development speed (very urgent demo)
good binding with C++ (I have legacy code I do not want to rewrite in another language)
smooth introduction of new programming language to team (has some python, java and perl knowledge)
What programming language fits my needs best, and why?
Details:
I lean towards python for its perfect binding with C++, as writing JNI is too much work, and kind of obsolete nowadays. However, no one in my team is Python programmer; I do know some Python (no experience in server side programming at all). I have been developing Java EE apps last year, but I do not think JNI is a good solution. Only one team member knows some Perl, others are pure C++ programmers. | Programming language decision for C++ legacy project workflow | 0 | 0 | 0 | 317 |
2,313,017 | 2010-02-22T18:11:00.000 | 2 | 1 | 0 | 1 | java,python,programming-languages,binding,java-native-interface | 2,313,312 | 3 | false | 0 | 0 | Given the urgency, I'd have to stick with C++.
Without that, I'd say keep what you got, but feel free to switch to a preferred language when refactoring. That would be the time to do it.
What you should not do, ever, is "port" anything to another language without rewriting or changing functionality in any way. It is a total waste of time, when the "best" outcome you can hope for is that it has no new bugs when you are done. | 3 | 1 | 0 | I have quite a lot of C++ legacy code modules from my colleagues, unfortunately poorly written. Each is doing a different job, but they are all GNU C++ code running under Linux.
I want to write a controller program, to make a singular C++ module for a workflow, for a very urgent demo. Also I need to write a front-end web-app allowing clients submitting jobs to the controller.
My main criteria are:
development speed (very urgent demo)
good binding with C++ (I have legacy code I do not want to rewrite in another language)
smooth introduction of new programming language to team (has some python, java and perl knowledge)
What programming language fits my needs best, and why?
Details:
I lean towards python for its perfect binding with C++, as writing JNI is too much work, and kind of obsolete nowadays. However, no one in my team is Python programmer; I do know some Python (no experience in server side programming at all). I have been developing Java EE apps last year, but I do not think JNI is a good solution. Only one team member knows some Perl, others are pure C++ programmers. | Programming language decision for C++ legacy project workflow | 0.132549 | 0 | 0 | 317 |
2,313,017 | 2010-02-22T18:11:00.000 | 3 | 1 | 0 | 1 | java,python,programming-languages,binding,java-native-interface | 2,313,159 | 3 | true | 0 | 0 | Noting the "very urgent demo" part, assuming that that would take about a month, depending on the complexity, I'd stick to the familiar.
True, maintaining python would be easier in the end, and learning python should be a breeze, if you deem it viable.
I'd say, have the team learn python and do the basic stuff, as you learn the deeper parts, you could build classes for them to extend/implement. That way, you get things done as they learn. | 3 | 1 | 0 | I have quite a lot of C++ legacy code modules from my colleagues, unfortunately poorly written. Each is doing a different job, but they are all GNU C++ code running under Linux.
I want to write a controller program, to make a singular C++ module for a workflow, for a very urgent demo. Also I need to write a front-end web-app allowing clients submitting jobs to the controller.
My main criteria are:
development speed (very urgent demo)
good binding with C++ (I have legacy code I do not want to rewrite in another language)
smooth introduction of new programming language to team (has some python, java and perl knowledge)
What programming language fits my needs best, and why?
Details:
I lean towards python for its perfect binding with C++, as writing JNI is too much work, and kind of obsolete nowadays. However, no one in my team is Python programmer; I do know some Python (no experience in server side programming at all). I have been developing Java EE apps last year, but I do not think JNI is a good solution. Only one team member knows some Perl, others are pure C++ programmers. | Programming language decision for C++ legacy project workflow | 1.2 | 0 | 0 | 317 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.