Q_CreationDate
stringlengths 23
23
| Title
stringlengths 11
149
| Question
stringlengths 25
6.53k
| Answer
stringlengths 15
5.1k
| Score
float64 -1
1.2
| Is_accepted
bool 2
classes | N_answers
int64 1
17
| Q_Id
int64 0
6.76k
|
---|---|---|---|---|---|---|---|
2009-04-29 08:28:24.667 | How to create IDLE -like functionality to WinForms application | I'd like to add "IDLE-like functionality" to C# WinForms application, but I don't quite have an idea how to do that and couldn't find anything useful with Google.
So basically I want interactive command line interface, where user could enter some Python code and execute it (not just expressions, should be possible to define new functions).
So, where to start? Are there any good tutorials or samples available? | IronRuby comes with a command line interpreter. Doesn't IronPython also have one? If so, the source code would be a good start :)
Oh, and if it doesn't, be sure to look at the IronRuby interpreter, because both languages are based on the DLR and are therefore similar enough to learn from both. | 0 | false | 1 | 153 |
2009-04-29 11:31:06.270 | Notifying container object: best practices | I have two classes: Account and Operator. Account contains a list of Operators. Now, whenever an operator (in the list) receives a message I want to notify Account object to perform some business logic as well.
I think of three alternatives on how to achieve this:
1) Hold a reference within Operator to the container [Account] object and call methods directly. Not absolutely good because of circular references.
2) Use events. As far as I know there is no built-in event handling mechanism in Python. So, this one is a bit tricky to implement.
3) Don't send messages to Operators directly. Instead, operate only Accounts, and within them, internally, handler operators. This one is a bit limiting because in this case I cannot pass around references to operators.
I wonder which approach is the most advantageous from the architectural point of view. How do you usually handle this task?
It would be great if you could point out snippets in Python. | You're over-thinking this. Seriously. Python isn't C++; your concerns are non-issues in Python. Just write what makes sense in your problem domain.
" Not absolutely good because of circular references."
Why not? Circularity is of no relevance here at all. Bidirectional relationships are great things. Use them. Python garbage collects them just fine without any thinking on your part.
What possible problem do you have with mutual (birectional) relationships?
"...operate only Accounts, and within them, internally, handler operators. This one is a bit limiting because in this case I cannot pass around references to operators.
"
What? Your Operators are Python objects, pass all you want. All Python objects are (in effect) references, don't sweat it.
What possible problem do you have with manipulating Operator objects? | 1.2 | true | 2 | 154 |
2009-04-29 11:31:06.270 | Notifying container object: best practices | I have two classes: Account and Operator. Account contains a list of Operators. Now, whenever an operator (in the list) receives a message I want to notify Account object to perform some business logic as well.
I think of three alternatives on how to achieve this:
1) Hold a reference within Operator to the container [Account] object and call methods directly. Not absolutely good because of circular references.
2) Use events. As far as I know there is no built-in event handling mechanism in Python. So, this one is a bit tricky to implement.
3) Don't send messages to Operators directly. Instead, operate only Accounts, and within them, internally, handler operators. This one is a bit limiting because in this case I cannot pass around references to operators.
I wonder which approach is the most advantageous from the architectural point of view. How do you usually handle this task?
It would be great if you could point out snippets in Python. | There is no "one-size-fits-all" solution for the Observer pattern. But usually, it's better to define an EventManager object where interested parties can register themselves for certain events and post these events whenever they happen. It simply creates less dependencies.
Note that you need to use a global EventManager instance, which can be problematic during testing or from a general OO point of view (it's a global variable). I strongly advise against passing the EventManager around all the time because that will clutter your code.
In my own code, the "key" for registering events is the class of the event. The EventManager uses a dictionary (event class -> list of observers) to know which event goes where. In the notification code, you can then use dict.get(event.__class__, ()) to find your listeners. | 0.240117 | false | 2 | 154 |
2009-04-30 05:03:05.993 | What is the best way to access stored procedures in Django's ORM | I am designing a fairly complex database, and know that some of my queries will be far outside the scope of Django's ORM. Has anyone integrated SP's with Django's ORM successfully? If so, what RDBMS and how did you do it? | I guess the improved raw sql queryset support in Django 1.2 can make this easier as you wouldn't have to roll your own make_instance type code. | 0 | false | 2 | 155 |
2009-04-30 05:03:05.993 | What is the best way to access stored procedures in Django's ORM | I am designing a fairly complex database, and know that some of my queries will be far outside the scope of Django's ORM. Has anyone integrated SP's with Django's ORM successfully? If so, what RDBMS and how did you do it? | Don't.
Seriously.
Move the stored procedure logic into your model where it belongs.
Putting some code in Django and some code in the database is a maintenance nightmare. I've spent too many of my 30+ years in IT trying to clean up this kind of mess. | 0.336246 | false | 2 | 155 |
2009-05-01 03:24:53.257 | Biggest python projects | What is the biggest software development team that uses Python? I am wondering how well the dynamic type system scales to large development teams.
It's pretty clear that at Google they have C++ and Java codebases with thousands of developers; their use of Python is much smaller.
Are there some huge companies that develop primarily in Python? | Python is very powerful language, Many big and the very high ranked websites are built on python..
Some big products of python are:-
Google (extensively used)
Youtube (extensively used)
Disqus
Eventbrite
Pinterest
Reddit
Quora
Mozilla
Asana (extensively used)
Dropbox (started with python, stayed with python)
Even Many companies are shifting their websites from PHP to Python, Because of its efficiency, fast ability, and reliability, and availability of huge support and many good frameworks such as Django..
Moreover, I am not saying that PHP is not a good server side scripting language, But truth is that, most users are adapting python instead of PHP. | 0.296905 | false | 3 | 156 |
2009-05-01 03:24:53.257 | Biggest python projects | What is the biggest software development team that uses Python? I am wondering how well the dynamic type system scales to large development teams.
It's pretty clear that at Google they have C++ and Java codebases with thousands of developers; their use of Python is much smaller.
Are there some huge companies that develop primarily in Python? | Our project is over 30,000 lines of Python. That's probably small by some standards. But it's plenty big enough to fill my little brain. The application is mentioned in our annual report, so it's "strategic" in that sense. We're not a "huge" company, so we don't really qualify.
A "huge company" (Fortune 1000?) doesn't develop primarily in any single language. Large companies will have lots of development teams, each using a different technology, depending on -- well -- on nothing in particular.
When you get to "epic companies" (Fortune 10) you're looking at an organization that's very much like a conglomerate of several huge companies rolled together. Each huge company within an epic company is still a huge company with multiple uncoordinated IT shops doing unrelated things -- there's no "develop primarily in" any particular language or toolset.
Even for "large companies" and "small companies" (like ours) you still have fragmentation. Our in-house IT is mostly Microsoft. Our other product development is mostly Java. My team, however, doesn't have much useful specification, so we use Python. We use python because of the duck typing and dynamic programming features.
(I don't know what a dynamic type system is -- Python types are static -- when you create an object, its type can never change.)
Since no huge company develops primarily in any particular language or toolset, the trivial answer to your question is "No" for any language or tool. And No for Python in particular. | 0.673066 | false | 3 | 156 |
2009-05-01 03:24:53.257 | Biggest python projects | What is the biggest software development team that uses Python? I am wondering how well the dynamic type system scales to large development teams.
It's pretty clear that at Google they have C++ and Java codebases with thousands of developers; their use of Python is much smaller.
Are there some huge companies that develop primarily in Python? | Among many other Python-centered companies, beyond the ones already mentioned by Unknown, I'd mention big pharma firms such as Astra-Zeneca, film studios such as Lucasfilm, and research places such as NASA, Caltech, Lawrence Livermore NRL.
Among the sponsors of Pycon Italia Tre (next week in Firenze, IT -- see www.pycon.it) are Qt/Trolltech (a wholly owned subsidiary of Nokia), Google of course, Statpro, ActiveState, Wingware -- besides, of course, several Italian companies.
Among the sponsors of Pycon US in Chicago in March were (of course) Google, as well as Sun Microsystems, Microsoft, Slide.com, Walt Disney Animation Studios, Oracle, Canonical, VMWare -- these are all companies who thought it worthwhile to spend money in order to have visibility to experienced Pythonistas, so presumably ones making significant large-scale use of Python (and in most cases trying to hire experienced Python developers in particular). | 0.995055 | false | 3 | 156 |
2009-05-04 08:59:20.273 | How can I check if an ip is in a network in Python? | Given an ip address (say 192.168.0.1), how do I check if it's in a network (say 192.168.0.0/24) in Python?
Are there general tools in Python for ip address manipulation? Stuff like host lookups, ip adddress to int, network address with netmask to int and so on? Hopefully in the standard Python library for 2.5. | #This works properly without the weird byte by byte handling
def addressInNetwork(ip,net):
'''Is an address in a network'''
# Convert addresses to host order, so shifts actually make sense
ip = struct.unpack('>L',socket.inet_aton(ip))[0]
netaddr,bits = net.split('/')
netaddr = struct.unpack('>L',socket.inet_aton(netaddr))[0]
# Must shift left an all ones value, /32 = zero shift, /0 = 32 shift left
netmask = (0xffffffff << (32-int(bits))) & 0xffffffff
# There's no need to mask the network address, as long as its a proper network address
return (ip & netmask) == netaddr | 0.029146 | false | 1 | 157 |
2009-05-05 02:52:08.900 | What's the best way to record the type of every variable assignment in a Python program? | Python is so dynamic that it's not always clear what's going on in a large program, and looking at a tiny bit of source code does not always help. To make matters worse, editors tend to have poor support for navigating to the definitions of tokens or import statements in a Python file.
One way to compensate might be to write a special profiler that, instead of timing the program, would record the runtime types and paths of objects of the program and expose this data to the editor.
This might be implemented with sys.settrace() which sets a callback for each line of code and is how pdb is implemented, or by using the ast module and an import hook to instrument the code, or is there a better strategy? How would you write something like this without making it impossibly slow, and without runnning afoul of extreme dynamism e.g side affects on property access? | What if you monkey-patched object's class or another prototypical object?
This might not be the easiest if you're not using new-style classes. | 0.101688 | false | 1 | 158 |
2009-05-05 16:22:53.010 | Network-aware wx.FileDialog | I'm using wx.FileDialog in a wxPython 2.8.8.0 application, under Xubuntu 8.10.. My problem is that this dialog isn't network-aware, so I can't browse Samba shares.
I see that this problem plagues other applications too (Firefox, Audacious...) so I'd like to ask where I could find informations on how to make it work.
Is that dialog supposed to be already network-aware? Am I missing something? Some library maybe? Or should I write my own implementation?
Many thanks! | Robin Dunn himself told me that
It's using the "native" GTK file
dialog, just like the other apps, so
there isn't anything that wx can do
about it.
So as a workaround I ended up installing gvfs-fuse and browsing
the network through $HOME/.gvfs.. A bit klunky but it works. | 1.2 | true | 1 | 159 |
2009-05-05 17:01:44.240 | Catch only some runtime errors in Python | I'm importing a module which raises the following error in some conditions:
RuntimeError: pyparted requires root access
I know that I can just check for root access before the import, but I'd like to know how to catch this spesific kind of error via a try/except statement for future reference. Is there any way to differentiate between this RuntimeError and others that might be raised? | I know that I can just check for root access before the import, but I'd like to know how to catch this spesific kind of error via a try/except statement for future reference. Is there any way to differentiate between this RuntimeError and others that might be raised?
If the error is caused by a specific condition, then I think the easiest way to catch the error is to test for the condition, and you can raise a more specific error yourself. After all the 'error' exists before the error is thrown, since in this case its a problem with the environment.
I agree with those above - text matching on an error is kind of a terrifying prospect. | 1.2 | true | 1 | 160 |
2009-05-05 20:14:11.267 | how to get the n-th record of a datastore query | Suppose that I have the model Foo in GAE and this query:
query = Foo.all().order('-key')
I want to get the n-th record. What is the most efficient way to achieve that?
Will the solution break if the ordering property is not unique, such as the one below:
query = Foo.all().order('-color')
edit: n > 1000
edit 2: I want to develop a friendly paging mechanism that shows pages available (such as Page 1, Page 2, ... Page 185) and requires a "?page=x" in the query string, instead of a "?bookmark=XXX". When page = x, the query is to fetch the records beginning from the first record of that page. | There is no efficient way to do this - in any DBMS. In every case, you have to at least read sequentially through the index records until you find the nth one, then look up the corresponding data record. This is more or less what fetch(count, offset) does in GAE, with the additional limitation of 1000 records.
A better approach to this is to keep a 'bookmark', consisting of the value of the field you're ordering on for the last entity you retrieved, and the entity's key. Then, when you want to continue from where you left off, you can add the field's value as the lower bound of an inequality query, and skip records until you match or exceed the last one you saw.
If you want to provide 'friendly' page offsets to users, what you can do is to use memcache to store an association between a start offset and a bookmark (order_property, key) tuple. When you generate a page, insert or update the bookmark for the entity following the last one. When you fetch a page, use the bookmark if it exists, or generate it the hard way, by doing queries with offsets - potentially multiple queries if the offset is high enough. | 1.2 | true | 1 | 161 |
2009-05-05 22:56:01.067 | Unit testing for D-Bus and HAL? | How does one test a method that does some interactions with the local D-Bus (accessing a HAL object)?
Results of tests will differ depending on the system that the test is run on, so I don't know how to provide the method reliable input.
I'm working in Python, by the way. | If you can not mock the environment then it's probably impossible for you to write the test.
If your access to HAL/D-Bus is via an object and you provide a mock instance to your test then it should be possible to emulate the necessary inputs to your test from the mock implementation. | 1.2 | true | 1 | 162 |
2009-05-07 07:45:26.073 | How to run a script without being in the tasktray? | I have a scheduled task which runs a python script every 10 min
so it turns out that a script pops up on my desktop every 10 min
how can i make it invincible so my script will work in the background ?
I've been told that pythonw will do the work, but I cant figure out how to use it
any help ?
thanks | Set the scheduled task to start the script as minimized. | 0 | false | 2 | 163 |
2009-05-07 07:45:26.073 | How to run a script without being in the tasktray? | I have a scheduled task which runs a python script every 10 min
so it turns out that a script pops up on my desktop every 10 min
how can i make it invincible so my script will work in the background ?
I've been told that pythonw will do the work, but I cant figure out how to use it
any help ?
thanks | I've been told that pythonw will do the work, but I cant figure out how to use it
Normally you just have to rename the file extension to .pyw. Then it will be executed by pythonw. | 0.545705 | false | 2 | 163 |
2009-05-07 20:55:48.750 | datastore transaction restrictions | in my google app application, whenever a user purchases a number of contracts, these events are executed (simplified for clarity):
user.cash is decreased
user.contracts is increased by the number
contracts.current_price is updated.
market.no_of_transactions is increased by 1.
in a rdms, these would be placed within the same transaction. I conceive that google datastore does not allow entities of more than one model to be in the same transaction.
what is the correct approach to this issue? how can I ensure that if a write fails, all preceding writes are rolled back?
edit: I have obviously missed entity groups. Now I'd appreciate some further information regarding how they are used. Another point to clarify is google says "Only use entity groups when they are needed for transactions. For other relationships between entities, use ReferenceProperty properties and Key values, which can be used in queries". does it mean I have to define both a reference property (since I need queriying them) and a parent-child relationship (for transactions)?
edit 2: and finally, how do I define two parents for an entity if the entity is being created to establish an n-to-n relationship between 2 parents? | After a through research, I have found that a distributed transaction layer that provides a solution to the single entity group restriction has been developed in userland with the help of some google people. But so far, it is not released and is only available in java. | 1.2 | true | 1 | 164 |
2009-05-08 18:23:39.907 | Tokenizing left over data with lex/yacc | Forgive me, I'm completely new to parsing and lex/yacc, and I'm probably in way over my head, but nonetheless:
I'm writing a pretty basic calculator with PLY, but it's input might not always be an equation, and I need to determine if it is or not when parsing. The extremes of the input would be something that evaluates perfectly to an equation, which it parses fine and calculates, or something that is nothing like an equation, which fails parsing and is also fine.
The gray area is an input that has equation-like parts, of which the parser will grab and work out. This isn't what I want - I need to be able to tell if parts of the string didn't get picked up and tokenized so I can throw back an error, but I have no idea how to do this.
Does anyone know how I can define, basically, a 'catch anything that's left' token? Or is there a better way I can handle this? | I typically use a separate 'command reader' to obtain a complete command - probably a line in your case - into a host variable string, and then arrange for the lexical analyzer to analyze the string, including telling me when it didn't reach the end. This is hard to set up, but make some classes of error reporting easier. One of the places I've used this technique routinely has multi-line commands with 3 comment conventions, two sets of quoted strings, and some other nasties to set my teeth on edge (context sensitive tokenization - yuck!).
Otherwise, Don's advice with the Yacc 'error' token is good. | 0 | false | 2 | 165 |
2009-05-08 18:23:39.907 | Tokenizing left over data with lex/yacc | Forgive me, I'm completely new to parsing and lex/yacc, and I'm probably in way over my head, but nonetheless:
I'm writing a pretty basic calculator with PLY, but it's input might not always be an equation, and I need to determine if it is or not when parsing. The extremes of the input would be something that evaluates perfectly to an equation, which it parses fine and calculates, or something that is nothing like an equation, which fails parsing and is also fine.
The gray area is an input that has equation-like parts, of which the parser will grab and work out. This isn't what I want - I need to be able to tell if parts of the string didn't get picked up and tokenized so I can throw back an error, but I have no idea how to do this.
Does anyone know how I can define, basically, a 'catch anything that's left' token? Or is there a better way I can handle this? | There is a built-in error token in yacc. You would normally do something like:
line: goodline | badline ;
badline : error '\n' /* Error-handling action, if needed */
goodline : equation '\n' ;
Any line that doesn't match equation will be handled by badline.
You might want to use yyerrok in the error handling action to ensure error processing is reset for the next line. | 1.2 | true | 2 | 165 |
2009-05-08 22:41:21.693 | Piping Batch File output to a Python script | I'm trying to write a python script (in windows) that runs a batch file and will take the command line output of that batch file as input. The batch file runs processes that I don't have access to and gives output based on whether those processes are successful. I'd like to take those messages from the batch file and use them in the python script. Anyone have any ideas on how to do this ? | Try subprocess.Popen(). It allows you to redirect stdout and stderr to files. | 0.135221 | false | 1 | 166 |
2009-05-11 12:24:35.110 | How to write a vb.net code to compile C/C++ programs? | I'm trying to make a vb.net application that has got 2 textboxes, 7 radio buttons and 2 buttons(one named compile and the other 'run'). How can I load the content of a C/C++(or any programming language) file into the 1st textbox and on clicking the compile button, i should be able to show the errors or the C/C++ program in the 2nd textbox. On clicking Run, I should be able to show the output in the 2nd textbox. In short, I want to use the 2nd textbox as a terminal/console. The radio buttons are 4 selecting the language C or C++ or python or C# or java or perl or vb.
Are the compilers of all these languages present in .net? If so how can I call them? | Compiling can be done by calling cl.exe which comes with Visual Studio. Of course you could also use GCC instead. | 0.201295 | false | 1 | 167 |
2009-05-11 14:55:46.930 | Python M2Crypto EC Support | M2Crypto provides EC support for ECDSA/ECDH. I have installed OpenSSL 0.9.8i which contains support for EC. However when I run "from M2Crypto import EC,BIO" I get error saying EC_init() failed. So I added debug to print m2.OPENSSL_VERSION_TEXT value. It gets printed as "OpenSSL 0.9.7 19 Feb 2003". This version of OpenSSL doesnot support EC.
I tried "python setup.py build build_ext --openssl="new_path where OpenSSL 0.9.8i is installed". Though M2Crypto is built again "Python setup.py install" , I still see that it points to "Old version of OpenSSL".
Any Pointers on how to successfully get M2Crypto to use 0.9.8i will be useful. | Possibly its looking up shared libs libssl.so and libcrypto.so and finding the old ones in /usr/lib if you add the new_path to the top of /etc/ld.so.conf so it gets searched first it would work. But this might break other OpenSSL applications expecting old OpenSSL. | 0 | false | 1 | 168 |
2009-05-12 03:20:00.953 | How do I check if a disk is in a drive using python? | Say I want to manipulate some files on a floppy drive or a USB card reader. How do I check to see if the drive in question is ready? (That is, has a disk physically inserted.)
The drive letter exists, so os.exists() will always return True in this case. Also, at this point in the process I don't yet know any file names, so checking to see if a given file exists also won't work.
Some clarification: the issue here is exception handling. Most of the win32 API calls in question just throw an exception when you try to access a drive that isn't ready. Normally, this would work fine - look for something like the free space, and then catch the raised exception and assume that means there isn't a disk present. However, even when I catch any and all exceptions, I still get an angry exception dialog box from Windows telling me the floppy / card reader isn't ready. So, I guess the real question is - how do I suppress the windows error box? | You can compare len(os.listdir("path")) to zero to see if there are any files in the directory. | 0.265586 | false | 1 | 169 |
2009-05-12 23:29:12.147 | Running django on OSX | I've just completed the very very nice django tutorial and it all went swimmingly. One of the first parts of the tutorial is that it says not to use their example server thingie in production, my first act after the tutorial was thus to try to run my app on apache.
I'm running OSX 10.5 and have the standard apache (which refuses to run python) and MAMP (which begrudgingly allows it in cgi-bin). The problem is that I've no idea which script to call, in the tutorial it was always localhost:8000/polls but I've no idea how that's meant to map to a specific file.
Have I missed something blatantly obvious about what to do with a .htaccess file or does the tutorial not actually explain how to use it somewhere else? | Unless you are planning on going to production with OS X you might not want to bother. If you must do it, go straight to mod_wsgi. Don't bother with mod_python or older solutions. I did mod_python on Apache and while it runs great now, it took countless hours to set up.
Also, just to clarify something based on what you said: You're not going to find a mapping between the url path (like /polls) and a script that is being called. Django doesn't work like that. With Django your application is loaded into memory waiting for requests. Once a request comes in it gets dispatched through the url map that you created in urls.py. That boils down to a function call somewhere in your code.
That's why for a webserver like Apache you need a module like mod_wsgi, which gives your app a spot in memory in which to live. Compare that with something like CGI where the webserver executes a specific script on demand at a location that is physically mapped between the url and the filesystem.
I hope that's helpful and not telling you something you already knew. :) | 0.470104 | false | 2 | 170 |
2009-05-12 23:29:12.147 | Running django on OSX | I've just completed the very very nice django tutorial and it all went swimmingly. One of the first parts of the tutorial is that it says not to use their example server thingie in production, my first act after the tutorial was thus to try to run my app on apache.
I'm running OSX 10.5 and have the standard apache (which refuses to run python) and MAMP (which begrudgingly allows it in cgi-bin). The problem is that I've no idea which script to call, in the tutorial it was always localhost:8000/polls but I've no idea how that's meant to map to a specific file.
Have I missed something blatantly obvious about what to do with a .htaccess file or does the tutorial not actually explain how to use it somewhere else? | Yet another option is to consider using a virtual machine for your development. You can install a full version of whatever OS your production server will be running - say, Debian - and run your Apache and DB in the VM.
You can connect to the virtual disk in the Finder, so you can still use TextMate (or whatever) on OSX to do your editing.
I've had good experiences doing this via VMWare Fusion. | 0.201295 | false | 2 | 170 |
2009-05-16 12:01:37.463 | Most Efficient Way to Find Whether a Large List Contains a Specific String (Python) | I have a file containing roughly all the words in English (~60k words, ~500k characters). I want to test whether a certain word I receive as input is "in English" (i.e. if this exact word is in the list).
What would be the most efficient way to do this in Python?
The trivial solution is to load the file into a list and check whether the word is in that list. The list can be sorted, which I believe will shrink the complexity to O(logn). However I'm not sure about how Python implements searching through lists, and whether there's a performance penalty if such a large list is in memory. Can I "abuse" the fact I can put a cap on the length of words? (e.g. say the longest one is 15 characters long).
Please note I run the application on a machine with lots of memory, so I care less for memory consumption than for speed and CPU utilization.
Thanks | You're basically testing whether a member is in a set or not, right?
If so, and because you said you have lots of memory, why not just load all the words as keys in memcache, and then for every word, just check if it is present in memcache or not.
Or use that data structure that is used by bash to autocomplete command names - this is fast and highly efficient in memory (can't remember the name). | 0.090455 | false | 2 | 171 |
2009-05-16 12:01:37.463 | Most Efficient Way to Find Whether a Large List Contains a Specific String (Python) | I have a file containing roughly all the words in English (~60k words, ~500k characters). I want to test whether a certain word I receive as input is "in English" (i.e. if this exact word is in the list).
What would be the most efficient way to do this in Python?
The trivial solution is to load the file into a list and check whether the word is in that list. The list can be sorted, which I believe will shrink the complexity to O(logn). However I'm not sure about how Python implements searching through lists, and whether there's a performance penalty if such a large list is in memory. Can I "abuse" the fact I can put a cap on the length of words? (e.g. say the longest one is 15 characters long).
Please note I run the application on a machine with lots of memory, so I care less for memory consumption than for speed and CPU utilization.
Thanks | Two things:
The Python 'mutable set' type has an 'add' method ( s.add(item) ), so you could go right from reading (a line) from your big file straight into a set without using a list as an intermediate data structure.
Python lets you 'pickle' a data structure, so you could save your big set to a file and save the time of reinitiating the set.
Second, I've been looking for a list of all the single-syllable words in English for my own amusement, but the ones I've found mentioned seem to be proprietary. If it isn't being intrusive, could I ask whether your list of English words can be obtained by others? | 0.090455 | false | 2 | 171 |
2009-05-16 16:19:40.790 | does someone know how to show content on screen (covering up any window) using Ruby or Python? | using Ruby or Python, does someone know how to draw on the screen, covering up any other window? Kind of like, press a key, and the program will show current weather or stock quote on the screen (using the whole screen as the canvas), and then press the key again, and everything restores to the same as before? (like Mac OS X's dash board). | I would recommend PyGame. | 0.135221 | false | 2 | 172 |
2009-05-16 16:19:40.790 | does someone know how to show content on screen (covering up any window) using Ruby or Python? | using Ruby or Python, does someone know how to draw on the screen, covering up any other window? Kind of like, press a key, and the program will show current weather or stock quote on the screen (using the whole screen as the canvas), and then press the key again, and everything restores to the same as before? (like Mac OS X's dash board). | You could use the systems dashboard (desktop widgets, or whatever it's called) API. In order to do that you need bindings to it for Python or Ruby.
Alternatively you could use some generic gui toolkit or application framework and just create a frameless window with transparent background. Then you need to be sure that the chosen toolkit supports 'always-on-top' options on your desired platform(s). | 1.2 | true | 2 | 172 |
2009-05-17 12:09:47.610 | Admin privileges for script | how can i check admin-privileges for my script during running? | The concept of "admin-privileges" in our day of fine grained privilege control is becoming hard to define. If you are running on unix with "traditional" access control model, getting the effective user id (available in os module) and checking that against root (0) could be what you are looking for. If you know accessing a file on the system requires the privileges you want your script to have, you can use the os.access() to check if you are privileged enough.
Unfortunately there is no easy nor portable method to give. You need to find out or define the security model used, what system provided APIs are available to query and set privileges and try to locate (or possibly implement yourself) the appropriate python modules that can be used to access the API.
The classic question, why do you need to find out? What if your script tries to do what it needs to do and "just" catches and properly handles failures? | 0.740859 | false | 1 | 173 |
2009-05-17 19:00:20.693 | Simple data storing in Python | I'm looking for a simple solution using Python to store data as a flat file, such that each line is a string representation of an array that can be easily parsed.
I'm sure python has library for doing such a task easily but so far all the approaches I have found seemed like it would have been sloppy to get it to work and I'm sure there is a better approach. So far I've tried:
the array.toFile() method but couldn't figure out how to get it to work with nested arrays of strings, it seemed geared towards integer data.
Lists and sets do not have a toFile method built in, so I would have had to parse and encode it manually.
CSV seemed like a good approach but this would also require manually parsing it, and did not allow me to simply append new lines at the end - so any new calls the the CSVWriter would overwrite the file existing data.
I'm really trying to avoid using databases (maybe SQLite but it seems a bit overkill) because I'm trying to develop this to have no software prerequisites besides Python. | I'm looking for a simple solution using Python to store data as a flat file, such that each line is a string representation of an array that can be easily parsed.
Is the data only ever going to be parsed by Python programs? If not, then I'd avoid pickle et al (shelve and marshal) since they're very Python specific. JSON and YAML have the important advantage that parsers are easily available for most any language. | 0.16183 | false | 1 | 174 |
2009-05-18 03:15:35.257 | PyQt: splash screen while loading "heavy" libraries | My PyQt application that uses matplotlib takes several seconds to load for the first time, even on a fast machine (the second load time is much shorter as the DLLs are kept in memory by Windows).
I'm wondering whether it's feasible to show a splash screen while the matplotlib library is being loaded. Where does the actual loading take place - is it when the from line is executed? If so, how can I make this line execute during the splash screen and still be able to use the module throughout the code?
A related dilemma is how to test this - can I ask Windows to load the DLLs for every execution and not cache them? | Yes, loading the module takes place at the line where the import statement is. If you create your QApplication and show your splash screen before that, you should be able to do what you want -- also you need to call QApplication.processEvents() whenever you need the splash screen to update with a new message. | 1.2 | true | 1 | 175 |
2009-05-20 01:22:36.397 | How does MySQL's RENAME TABLE statment work/perform? | MySQL has a RENAME TABLE statemnt that will allow you to change the name of a table.
The manual mentions
The rename operation is done atomically, which means that no other session can
access any of the tables while the rename is running
The manual does not (to my knowedge) state how this renaming is accomplished. Is an entire copy of the table created, given a new name, and then the old table deleted? Or does MySQL do some magic behind the scenes to quickly rename the table?
In other words, does the size of the table have an effect on how long the RENAME table statement will take to run. Are there other things that might cause the renaming of a block to significantly block? | I believe MySQL only needs to alter metadata and references to the table's old name in stored procedures -- the number of records in the table should be irrelevant. | 1.2 | true | 1 | 176 |
2009-05-25 12:16:07.597 | show lyrics on ubuntu | I'm writing a little script for Ubuntu.
My intention is to call rhythmbox lyrics plug-in with a global short-cut (configuring gnome) .
I can call it from rhythmbox python console, but I don't know how to import rhythmbox built-in modules (eg. rhythmdb).
Any ideas? | You can't import rhythmbox "built-in" modules from a standard python console.
As far as I know they aren't real modules, they are just objects from the rhythmbox process exposed to plugins. So you can access them only if you are running your script from the rhythmbox process. | 0.386912 | false | 2 | 177 |
2009-05-25 12:16:07.597 | show lyrics on ubuntu | I'm writing a little script for Ubuntu.
My intention is to call rhythmbox lyrics plug-in with a global short-cut (configuring gnome) .
I can call it from rhythmbox python console, but I don't know how to import rhythmbox built-in modules (eg. rhythmdb).
Any ideas? | in this case i guess you'll have to write the whole plugin yourself and , then listen to dbus for change of songs in rhythmbox , to detect which song is being played . | 0 | false | 2 | 177 |
2009-05-25 18:05:23.203 | Making a Python script executable chmod755? | My hosting provider says my python script must be made to be executable(chmod755). What does this mean & how do I do it?
Cheers! | In addition to the other fine answers here, you should be aware that most FTP clients have a chmod command to allow you to set permissions on files at the server. You may not need this if permissions come across properly, but there's a good chance they do not. | 0 | false | 1 | 178 |
2009-05-28 14:55:26.907 | How to compare data of two tables transformed in SSIS package | A table has been ETLed to another table. My task is to verify the data between two tables programmatically.
One of the difficulties I m facing rite now is:
how to use the expression that I can get from, let s say, derived column task and verify with the source and destination.
or in other words, how can I use the expression to work in the code.
Any ideas....highly appreciated
Sagar | Set up a column which holds a CHECKSUM() of each row. Do a left outer join between the two tables . If you have any nulls for the right side, you have problems. | 0.673066 | false | 1 | 179 |
2009-06-01 07:14:45.760 | Packaging script source files in IronPython and IronRuby | Does anyone know how to add python and ruby libs as a resource in a dll for deployment? I want to host a script engine in my app, but dont want to have to deploy the entire standard libraries of the respective languages in source files. Is there a simple way to do this so that a require or import statement will find the embedded resources? | IronPython 2.0 has a sample compiler called PYC on Codeplex.com/ironpython which can create DLL's (and applications if you need them too).
IronPython 2.6 has a newer version of PYC under Tools\script.
Cheers,
Davy | 0 | false | 2 | 180 |
2009-06-01 07:14:45.760 | Packaging script source files in IronPython and IronRuby | Does anyone know how to add python and ruby libs as a resource in a dll for deployment? I want to host a script engine in my app, but dont want to have to deploy the entire standard libraries of the respective languages in source files. Is there a simple way to do this so that a require or import statement will find the embedded resources? | You could add custom import hook that looks for embedded resources when an import is executed. This is slightly complex and probably not worth the trouble.
A better technique would be to fetch all of the embedded modules at startup time, execute them with the ScriptEngine and put the modules you have created into the sys.modules dictionary associated with the engine. This automatically makes them available for import by Python code executed by the engine. | 0.135221 | false | 2 | 180 |
2009-06-03 13:19:54.927 | How can I check for NaN values? | float('nan') represents NaN (not a number). But how do I check for it? | numpy.isnan(number) tells you if it's NaN or not. | 1 | false | 1 | 181 |
2009-06-04 17:51:31.243 | Recursive Function palindrome in Python | I need help writing a recursive function which detects whether a string is a palindrome. But i can't use any loops it must be recursive. Can anyone help show me how this is done . Im using Python. | If a string is zero or one letters long, it's a palindrome.
If a string has the first and last letters the same, and the remaining letters (I think it's a [1: -1] slice in Python, but my Python is a bit rusty) are a palindrome, it's a palindrome.
Now, write that as a palindrome function that takes a string. It will call itself. | 0.11086 | false | 2 | 182 |
2009-06-04 17:51:31.243 | Recursive Function palindrome in Python | I need help writing a recursive function which detects whether a string is a palindrome. But i can't use any loops it must be recursive. Can anyone help show me how this is done . Im using Python. | Here's another viewpoint
A palindromic string is
Some letter, x.
Some palindromic substrinng.
The same letter, x, repeated.
Also, note that you may be given a proper English sentence "Able was I ere I saw Elba." with punctuation. Your palindrome checker may have to quietly skip punctuation. Also, you may have to quietly match without considering case. This is slightly more complex.
Some leading punctuation. Some letter, x.
Some palindromic substring.
Some letter, x, repeated without regard to case. Some trailing punctuation.
And, by definition, a zero-length string is a palindrome. Also a single-letter string (after removing punctuation) is a palindrome. | 0.074076 | false | 2 | 182 |
2009-06-06 20:33:32.037 | how can I add a QMenu and QMenuItems to a window from Qt Designer | Is there any reason why a QMenu cannot be added from the Qt Designer? I find it weird that you can add other widget types but not this. | I have a single main window with a QGraphicsView and lots of QGraphicsItem objects. Each type of the Items have a different context menu.
I find that not being able to create the contextMenu's, or at least the actions that are in them a serious limitation of QtDesigner. It means that I can create about 10% or so of the actions using the designer, and I have to create 90% programaticaly. Compare that with the Microsoft resource editor which allows all of these things to be created, and maintained effortlessly.
I hope this will be addressed at some point. | 0.386912 | false | 3 | 183 |
2009-06-06 20:33:32.037 | how can I add a QMenu and QMenuItems to a window from Qt Designer | Is there any reason why a QMenu cannot be added from the Qt Designer? I find it weird that you can add other widget types but not this. | When you edit a QMainWindow you can right click the window and then choose "create menu bar".
Or are you talking about a "context menu" aka "right click menu"? | 1.2 | true | 3 | 183 |
2009-06-06 20:33:32.037 | how can I add a QMenu and QMenuItems to a window from Qt Designer | Is there any reason why a QMenu cannot be added from the Qt Designer? I find it weird that you can add other widget types but not this. | Adding menu editing for every widget in the designer would probably make a very awkward and inconvenient UI. There's really no place you can visualize it on.
If you're editing a QMainWindow you can edit the menu bar and its popups because there's a proper place for them to be displayed in. | 0 | false | 3 | 183 |
2009-06-08 11:30:28.043 | how to remove text between using python? | how to remove text between <script> and </script> using python? | If you're removing everything between <script> and </script> why not just remove the entire node?
Are you expecting a resig-style src and body? | 0 | false | 2 | 184 |
2009-06-08 11:30:28.043 | how to remove text between using python? | how to remove text between <script> and </script> using python? | I don't know Python good enough to tell you a solution. But if you want to use that to sanitize the user input you have to be very, very careful. Removing stuff between and just doesn't catch everything. Maybe you can have a look at existing solutions (I assume Django includes something like this). | -0.04532 | false | 2 | 184 |
2009-06-09 00:29:59.137 | python truncate after a hundreds? | How can truncate an input like 315.15321531321
I want to truncate all the values after the hundredths position so it becomes 315.15
how do i do that? | You have several options - you can round the number using round(), however this can introduce some inaccuracies (315.15 might round to 315.150000003 for example). If you're just looking to truncate the value of the float when you're displaying it, you can specify the width of the output using printf("%.2f", mynumber). This is probably a better solution, since without knowing more about your specific application it's a good idea in general to keep the entire length of the number for calculation. | 0.050976 | false | 1 | 185 |
2009-06-09 19:18:06.150 | Django - Website Home Page | I've been having a look at Django and, from what I've seen, it's pretty darn fantastic. I'm a little confused, however, how I go about implementing a "home page" for my website? Would it be a separate app, or just a view within the project, or what? | There's no real rule for this, But one thing I like to do is actually arrange for the index access to redirect to another spot. If you prefer, though, you can just give the index page a plain view.
That said, It's probably a good idea to keep all your code in an actual app, so that you can refactor it more easily, and so that it appears on the python path as a normal module. Putting views in the project rather than an app seems to cause more headaches than it solves. | 1.2 | true | 1 | 186 |
2009-06-10 03:11:55.320 | how to integrate ZSH and (i)python? | I have been in love with zsh for a long time, and more recently I have been discovering the advantages of the ipython interactive interpreter over python itself. Being able to cd, to ls, to run or to ! is indeed very handy. But now it feels weird to have such a clumsy shell when in ipython, and I wonder how I could integrate my zsh and my ipython better.
Of course, I could rewrite my .zshrc and all my scripts in python, and emulate most of my shell world from ipython, but it doesn't feel right. And I am obviously not ready to use ipython as a main shell anyway.
So, here comes my question: how do you work efficiently between your shell and your python command-loop ? Am I missing some obvious integration strategy ? Should I do all that in emacs ? | I asked this question on the zsh list and this answer worked for me. YMMV.
In genutils.py after the line
if not debug:
Remove the line:
stat = os.system(cmd)
Replace it with:
stat =
subprocess.call(cmd,shell=True,executable='/bin/zsh')
you see, the problem is that that "!" call uses os.system to run it, which defaults to manky old /bin/sh .
Like I said, it worked for me, although I'm not sure what got borked behind the scenes. | 1.2 | true | 1 | 187 |
2009-06-10 10:42:38.667 | python not starting properly | I have installed python and django in my system that uses win vista. Now when I go to command prompt and type python or django-admin.py both are not working. Every time I need to set the path to the python folder manually. But i have seen these commands running even without setting path. So how do i make it to run properly? | In your path, I think you need to have both the location of the Python install and the Python\Scripts folder. For example, on XP, I have C:\Python25;C:\Python25\Scripts. Can you verify that you have both? | 0 | false | 3 | 188 |
2009-06-10 10:42:38.667 | python not starting properly | I have installed python and django in my system that uses win vista. Now when I go to command prompt and type python or django-admin.py both are not working. Every time I need to set the path to the python folder manually. But i have seen these commands running even without setting path. So how do i make it to run properly? | Either use the system control panel to set the PATH environment variable that applies permanently or
Reinstall Python as a system administrator so that the installer can set the registry and environment variables for you.
If you install the "just for me" option, then you have to set the PATH variable in the control panel. | 1.2 | true | 3 | 188 |
2009-06-10 10:42:38.667 | python not starting properly | I have installed python and django in my system that uses win vista. Now when I go to command prompt and type python or django-admin.py both are not working. Every time I need to set the path to the python folder manually. But i have seen these commands running even without setting path. So how do i make it to run properly? | you can't run a command that isn't in your path. it should be set globally when you installed python.
type 'set' at a dos prompt and look at the PATH variable. c:\python25 (or whever you installed python) has to be in that variable ie PATH=c:\windows;c:\python25;... etc
if it isn't in PATH then you or the installer missed the part where you needed to set it. It can be done from the 'Environment Variables' button in the 'System' control panel. | 0.101688 | false | 3 | 188 |
2009-06-10 23:35:16.360 | Vim, Python, and Django autocompletion (pysmell?) | Does anyone know how to set up auto completion to work nicely with python, django, and vim?
I've been trying to use pysmell, but I can't seem to get it set up correctly (or maybe I don't know how it works). Right now, I run pysmell in the django directory (I'm using the trunk) and move the resulting tags to my project directory, then I also run pysmell in the project directory. Vim doesn't pick up the django tags, though, and they don't get auto completed.
Does anyone know how to set up auto completion in vim so that it will complete the long django functions (like get_object_or_404) as well as classes/functions in my own code? I have poked around on google but haven't found any good resources.
Thanks. | I've had good luck with exuberant-ctags for this.
I use this macro in my vimrc:
execute 'map :!/usr/bin/exuberant-ctags -f '.&tags.' --recurse '.$_P4ROOT.' '
You'll want to modify that slightly, so that it includes your python /site-packages/django/ directory as well as your own code.
Then, hit F2 inside vim to update the tags, and use the regular vim tag bindings to navigate. | 0.240117 | false | 2 | 189 |
2009-06-10 23:35:16.360 | Vim, Python, and Django autocompletion (pysmell?) | Does anyone know how to set up auto completion to work nicely with python, django, and vim?
I've been trying to use pysmell, but I can't seem to get it set up correctly (or maybe I don't know how it works). Right now, I run pysmell in the django directory (I'm using the trunk) and move the resulting tags to my project directory, then I also run pysmell in the project directory. Vim doesn't pick up the django tags, though, and they don't get auto completed.
Does anyone know how to set up auto completion in vim so that it will complete the long django functions (like get_object_or_404) as well as classes/functions in my own code? I have poked around on google but haven't found any good resources.
Thanks. | Today, you not need special extentions for django autocomplete in vim. Make sure that you have vim with python support.
To check it, type in xterm:
vim --version|grep python
output:
+python -python3 +quickfix +reltime +rightleft -ruby +scrollbind +signs ... ...
To make work autocomplete, add this lines in your .vimrc:
autocmd FileType python set omnifunc=pythoncomplete#Complete
if has("python")
python import sys,os
python sys.path.append('/home/sergey/workspace/django')
python os.environ['DJANGO_SETTINGS_MODULE'] = 'djangoProject.settings'
endif
where:
sys.path.append is path to your django workspace directory
djangoProject is name of your django project, which is going just after '/home/sergey/workspace/django'
Finally, save it and restart vim. Now, after '.', you press default ctrl-x ctrl-o to get your autocomplete. | 0.16183 | false | 2 | 189 |
2009-06-12 05:28:54.720 | How to specify native library search path for python | I have installed lxml which was built using a standalone version of libxml2. Reason for this was that the lxml needed a later version of libxml2 than what was currently installed.
When I use the lxml module how do I tell it (python) where to find the correct version of the libxml2 shared library? | Assuming you're talking about a .so file, it's not up to Python to find it -- it's up to the operating system's dynamic library loaded. For Linux, for example, LD_LIBRARY_PATH is the environment variable you need to set. | 1.2 | true | 1 | 190 |
2009-06-15 09:15:37.030 | Using python regex to extract namespaces from C++ sources | I am trying to extract the namespaces defined in C++ files.
Basically, if my C++ file contains:
namespace n1 {
...
namespace n2 { ... } // end namespace n2
...
namespace n3 { ...} //end namespace n3
...
} //end namespace n1
I want to be able to retrieve: n1, n1::n2, n1::n3.
Does someone have any suggestion of how I could do that using python-regex?
Thanks. | The need is simple enough that you may not need a complex parser. You need to:
extract the namespace names
count the open/close braces to keep track of where your namespace is defined.
This simple approach works if the other conditions are met:
you don't get spurious namespace like strings inside comments or inside strings
you don't get unmatched open/closeing braces inside comments or strings
I don't think this is too much asking from your source. | 0.135221 | false | 5 | 191 |
2009-06-15 09:15:37.030 | Using python regex to extract namespaces from C++ sources | I am trying to extract the namespaces defined in C++ files.
Basically, if my C++ file contains:
namespace n1 {
...
namespace n2 { ... } // end namespace n2
...
namespace n3 { ...} //end namespace n3
...
} //end namespace n1
I want to be able to retrieve: n1, n1::n2, n1::n3.
Does someone have any suggestion of how I could do that using python-regex?
Thanks. | Searching for the namespace names is pretty easy with a regular expression. However, to determine the nesting level you will have to keep track of the curly bracket nesting level in the source file. This is a parsing problem, one that cannot be solved (sanely) with regular expressions. Also, you may have to deal with any C preprocessor directives in the file which can definitely affect parsing.
C++ is a notoriously tricky language to parse completely, but you may be able to get by with a tokeniser and a curly bracket counter. | 0.386912 | false | 5 | 191 |
2009-06-15 09:15:37.030 | Using python regex to extract namespaces from C++ sources | I am trying to extract the namespaces defined in C++ files.
Basically, if my C++ file contains:
namespace n1 {
...
namespace n2 { ... } // end namespace n2
...
namespace n3 { ...} //end namespace n3
...
} //end namespace n1
I want to be able to retrieve: n1, n1::n2, n1::n3.
Does someone have any suggestion of how I could do that using python-regex?
Thanks. | You could write a basic lexer for it. It's not that hard. | 0.067922 | false | 5 | 191 |
2009-06-15 09:15:37.030 | Using python regex to extract namespaces from C++ sources | I am trying to extract the namespaces defined in C++ files.
Basically, if my C++ file contains:
namespace n1 {
...
namespace n2 { ... } // end namespace n2
...
namespace n3 { ...} //end namespace n3
...
} //end namespace n1
I want to be able to retrieve: n1, n1::n2, n1::n3.
Does someone have any suggestion of how I could do that using python-regex?
Thanks. | Most of the time when someone asks how to do something with regex, they're doing something very wrong. I don't think this case is different.
If you want to parse c++, you need to use a c++ parser. There are many things that can be done that will defeat a regex but still be valid c++. | 0 | false | 5 | 191 |
2009-06-15 09:15:37.030 | Using python regex to extract namespaces from C++ sources | I am trying to extract the namespaces defined in C++ files.
Basically, if my C++ file contains:
namespace n1 {
...
namespace n2 { ... } // end namespace n2
...
namespace n3 { ...} //end namespace n3
...
} //end namespace n1
I want to be able to retrieve: n1, n1::n2, n1::n3.
Does someone have any suggestion of how I could do that using python-regex?
Thanks. | That is what I did earlier today:
Extract the comment out of the C++ files
Use regex to extract the namespace definition
Use a simple string search to get the open & close braces positions
The various sanity check added show that I am successfully processing 99.925% of my files (5 failures ouf of 6678 files). The issues are due to mismatches in numbers of { and } cause by few '{' or '}' in strings, and unclean usage of the preprocessor instruction.
However, I am only dealing with header files, and I own the code. That limits the number of scenari that could cause some issues and I can manually modify the ones I don't cover.
Of course I know there are plenty of cases where it would fail but it is probably enough for what I want to achieve.
Thanks for your answers. | 0 | false | 5 | 191 |
2009-06-15 19:25:28.390 | System theme icons and PyQt4 | I'm writing a basic program in python using the PyQt4 module. I'd like to be able to use my system theme's icons for things like the preference dialog's icon, but i have no idea how to do this. So my question is, how do you get the location of an icon, but make sure it changes with the system's icon theme? If it matters, i'm developing this under ubuntu 9.04, so i am using the gnome desktop. | I spent a decent amount of researching this myself not long ago, and my conclusion was that, unfortunately, Qt doesn't provide this functionality in a cross-platform fashion. Ideally the QIcon class would have defaults for file open, save, '+', '-', preferences, etc, but considering it doesn't you'll have to grab the appropriate icon for your desktop environment. | 0 | false | 1 | 192 |
2009-06-16 14:09:44.313 | How To Reversibly Store Password With Python On Linux? | First, my question is not about password hashing, but password encryption. I'm building a desktop application that needs to authentificate the user to a third party service. To speed up the login process, I want to give the user the option to save his credentials. Since I need the password to authentificate him to the service, it can't be hashed.
I thought of using the pyCrypto module and its Blowfish or AES implementation to encrypt the credentials. The problem is where to store the key. I know some applications store the key directly in the source code, but since I am coding an open source application, this doesn't seem like a very efficient solution.
So I was wondering how, on Linux, you would implement user specific or system specific keys to increase password storing security.
If you have a better solution to this problem than using pyCrypto and system/user specific keys, don't hesitate to share it. As I said before, hashing is not a solution and I know password encryption is vulnerable, but I want to give the option to the user. Using Gnome-Keyring is not an option either, since a lot of people (including myself) don't use it. | Encrypting the passwords doesn't really buy you a whole lot more protection than storing in plaintext. Anyone capable of accessing the database probably also has full access to your webserver machines.
However, if the loss of security is acceptable, and you really need this, I'd generate a new keyfile (from a good source of random data) as part of the installation process and use this. Obviously store this key as securely as possible (locked down file permissions etc). Using a single key embedded in the source is not a good idea - there's no reason why seperate installations should have the same keys. | 1.2 | true | 1 | 193 |
2009-06-16 18:50:48.037 | Number of visitors in Django | In Django, how can I see the number of current visitors? Or how do I determine the number of active sessions?
Is this a good method?
use django.contrib.sessions.models.Session, set the expiry time short. Every time when somebody does something on the site, update expiry time. Then count the number of sessions that are not expired. | Edit: Added some more information about why I present this answer here. I found chartbeat when I tried to answer this same question for my django based site. I don't work for them.
Not specifically Django, but chartbeat.com is very interesting to add to a website as well.
django-tracking is great, +1 for that answer, etc.
Couple of things I could not do with django-tracking, that chartbeat helped with; tracked interactions with completely cached pages which never hit the django tracking code and pages not delivered through django (e.g. wordpress, etc.) | -0.201295 | false | 1 | 194 |
2009-06-18 17:57:24.017 | wxPython: how to make two toolbars use one statusbar for tooltips? | I have an interface that has two toolbars, one attached to the frame and one embedded in a notebook tab. The one in the frame dutifully shows longHelp strings in the statusbar, the one in the notebook tab
does not. How do I tell the one on the notebook tab where to display its help, or do I have to manage enter and leave bindings myself? | from wxPython docs
"""
longHelpString
This string is shown in the statusbar (if any) of the parent frame when the mouse pointer is inside the tool
"""
so toolbar in notebook doesn't get any statusbar to display long help, so either thru src we should invertigate how it inquires abt status bar and supply a ref to main frame status bar
else i think better way is to just override wxToolBar::OnMouseEnter and display help directly on status bar | 0 | false | 1 | 195 |
2009-06-19 04:04:12.297 | Synthesis of general programming language (Python) with tailored language (PureData/MaxMSP/ChucK) | I am learning Python because it appeals to me as a mathematician but also has many useful libraries for scientific computing, image processing, web apps, etc etc.
It is frustrating to me that for certain of my interests (eletronic music or installation art) there are very specific programming languages which seem better suited to these purposes, such as Max/MSP, PureData, and ChucK -- all quite fascinating.
My question is, how should one approach these different languages? Should I simply learn Python and manage the others by using plugins and Python interpreters in them? Are there good tools for integrating the languages, or is the proper way simply to learn all of them? | I would say learn them all. While it's true that many languages can do many things, specialised languages are usually more expressive and easier to use for a particular task. Case-in-point is while most languages allow shell interaction and process control very few are as well suited to the task as bash scripts.
Plugins and libraries can bridge the gap between general and specialised languages but in my experience this is not always without drawbacks - be they speed, stability or complexity. It isn't uncommon to have to compile additional libraries or apply patches or use untrusted and poorly supported modules. It also isn't uncommon that the resulting interface is still harder to use than the original language.
I know about 15 languages well and a few of those very well. I do not use my prefered languages when another is more suitable. | 1.2 | true | 2 | 196 |
2009-06-19 04:04:12.297 | Synthesis of general programming language (Python) with tailored language (PureData/MaxMSP/ChucK) | I am learning Python because it appeals to me as a mathematician but also has many useful libraries for scientific computing, image processing, web apps, etc etc.
It is frustrating to me that for certain of my interests (eletronic music or installation art) there are very specific programming languages which seem better suited to these purposes, such as Max/MSP, PureData, and ChucK -- all quite fascinating.
My question is, how should one approach these different languages? Should I simply learn Python and manage the others by using plugins and Python interpreters in them? Are there good tools for integrating the languages, or is the proper way simply to learn all of them? | This thread is a little old, but I wanted to point out that the majority of the mature audio development environments e.g. supercollider/max-msp/pure data can be controlled via open sound control. You can google up a better description of OSC, but suffice it to say that it allows you to send control data to synths built in these environments similar to how MIDI works, but way more extensive. This does not solve the problem of actually building synths in python per se but it allows you to "drive" these other environments without having to know the ins and outs of the language. | 0.386912 | false | 2 | 196 |
2009-06-19 19:35:07.567 | Sandboxing in Linux | I want to create a Web app which would allow the user to upload some C code, and see the results of its execution (the code would be compiled on the server). The users are untrusted, which obviously has some huge security implications.
So I need to create some kind of sandbox for the apps. At the most basic level, I'd like to restrict access to the file system to some specified directories. I cannot use chroot jails directly, since the web app is not running as a privileged user. I guess a suid executable which sets up the jail would be an option.
The uploaded programs would be rather small, so they should execute quickly (a couple of seconds at most). Hence, I can kill the process after a preset timeout, but how do I ensure that it doesn't spawn new processes? Or if I can't, is killing the entire pgid a reliable method?
What would be the best way to go about this - other than "don't do it at all"? :) What other glaring security problems have I missed?
FWIW, the web app will be written in Python. | Spawning a new VM under KVM or qemu to compile and run the code looks like the way to go. Running the code under jail/LXC can compromise the machine if it exploits the unsecured parts of the OS like networking code. Advantage of running under a VM are obvious. One can only hack the VM but not the machine itself. But the side effect is you need lots of resources (CPU and Memory) to spawn a VM for each request. | 0 | false | 3 | 197 |
2009-06-19 19:35:07.567 | Sandboxing in Linux | I want to create a Web app which would allow the user to upload some C code, and see the results of its execution (the code would be compiled on the server). The users are untrusted, which obviously has some huge security implications.
So I need to create some kind of sandbox for the apps. At the most basic level, I'd like to restrict access to the file system to some specified directories. I cannot use chroot jails directly, since the web app is not running as a privileged user. I guess a suid executable which sets up the jail would be an option.
The uploaded programs would be rather small, so they should execute quickly (a couple of seconds at most). Hence, I can kill the process after a preset timeout, but how do I ensure that it doesn't spawn new processes? Or if I can't, is killing the entire pgid a reliable method?
What would be the best way to go about this - other than "don't do it at all"? :) What other glaring security problems have I missed?
FWIW, the web app will be written in Python. | I think your solutions must concentrate on analyzing the source code. I don't know any tools, and I think this would be pretty hard with C, but, for example, a Pascal program which doesn't include any modules would be pretty harmless in my opinion. | 0 | false | 3 | 197 |
2009-06-19 19:35:07.567 | Sandboxing in Linux | I want to create a Web app which would allow the user to upload some C code, and see the results of its execution (the code would be compiled on the server). The users are untrusted, which obviously has some huge security implications.
So I need to create some kind of sandbox for the apps. At the most basic level, I'd like to restrict access to the file system to some specified directories. I cannot use chroot jails directly, since the web app is not running as a privileged user. I guess a suid executable which sets up the jail would be an option.
The uploaded programs would be rather small, so they should execute quickly (a couple of seconds at most). Hence, I can kill the process after a preset timeout, but how do I ensure that it doesn't spawn new processes? Or if I can't, is killing the entire pgid a reliable method?
What would be the best way to go about this - other than "don't do it at all"? :) What other glaring security problems have I missed?
FWIW, the web app will be written in Python. | About the only chance you have is running a VirtualMachine and those can have vulnerabilities. If you want your machine hacked in the short term just use permissions and make a special user with access to maybe one directory. If you want to postpone the hacking to some point in the future then run a webserver inside a virtual machine and port forward to that. You'll want to keep a backup of that because you'll probably have that hacked in under an hour and want to restart a fresh copy every few hours. You'll also want to keep an image of the whole machine to just reimage the whole thing once a week or so in order to overcome the weekly hackings. Don't let that machine talk to any other machine on your network. Blacklist it everywhere. I'm talking about the virtual machine and the physical machine IP addresses. Do regular security audits on any other machines on your other machines on the network. Please rename the machines IHaveBeenHacked1 and IHaveBeenHacked2 and prevent access to those in your hosts lists and firewalls.
This way you might stave off your level of hackage for a while. | -0.067922 | false | 3 | 197 |
2009-06-21 23:31:10.947 | What's the best way to implement web service for ajax autocomplete | I'm implementing a "Google Suggest" like autocomplete feature for tag searching using jQuery's autocomplete.
I need to provide a web service to jQuery giving it a list of suggestions based on what the user has typed. I see 2 ways of implementing the web service:
1) just store all the tags in a database and search the DB using user input as prefix. This is simple, but I'm concerned about latency.
2) Use an in-process trie to store all the tags and search it for matching results. As everything will be in-process, I expect this to have much lower latency. But there are several difficulties:
-What's a good way to initialize the trie on process start up? Presumable I'll store the tag data in a DB and retrieve them and turn them into a trie when I frist start up the process. But I'm not sure how. I'm using Python/Django.
-When a new tag is created by a user, I need to insert the new tag into the trie. But let's say I have 5 Django processes and hence 5 tries, how do I tell the other 4 tries that they need to insert a new tag too?
-How to make sure the trie is threadsafe as my Django processes will be threaded (I'm using mod_wsgi). Or do I not have to worry about threadsafty because of Python's GIL?
-Any way I can store the tag's frequency of use within the trie as well? How do I tell when does the tag's string end and when does the frequency start - eg. if I store apple213 into the trie, is it "apple" with frequency 213 or is it "apple2" with frequency 13??
Any help on the issues above or any suggestions on a different approach would be really appreciated. | I would use the first option. 'KISS' - (Keep It Simple Stupid).
For small amounts of data there shouldn't be much latency. We run the same kind of thing for a name search and results appear pretty quickly on a few thousand rows.
Hope that helps,
Josh | 0.201295 | false | 1 | 198 |
2009-06-23 14:24:51.560 | how to addreference to Ritmo for iSeries in ironpython | I was just wondering if anybody knows how to add reference to "Ritmo for iSeries" in IronPython.
I did it successfully in C# and get it to work (since it is just click click click) And I was trying to do the same in IronPython but it says, "could not add reference to assembly Ritmo for iSeries".
I was doing
import clr
clr.AddReference('Ritmo for iSeries')
from Ritmo........
IOError: Could not add reference to assembly Ritmo for iSeries | Jonathan helped me to figure out that I had not copied the dll file to the location where IronPython can find it.
After copying the dll file to the location, usually it s "c:\Program Files\IronPython 2.0\"
unless stated otherwise, I did:
import clr
clr.AddReference('System.Data')
clr.AddReferenceToFile('Sql400.dll')
from System.Data import Sql400
from System.Data.Sql400 import * | 0 | false | 2 | 199 |
2009-06-23 14:24:51.560 | how to addreference to Ritmo for iSeries in ironpython | I was just wondering if anybody knows how to add reference to "Ritmo for iSeries" in IronPython.
I did it successfully in C# and get it to work (since it is just click click click) And I was trying to do the same in IronPython but it says, "could not add reference to assembly Ritmo for iSeries".
I was doing
import clr
clr.AddReference('Ritmo for iSeries')
from Ritmo........
IOError: Could not add reference to assembly Ritmo for iSeries | You need to use the actual name of the assembly (it won't have spaces).
In your C# project, what does it list under the 'references' folder once you've added it as a reference? Try putting that. Also, make sure you've copied the dll for the library to where your IronPython script can find it (if it's not in the GAC). | 0 | false | 2 | 199 |
2009-06-24 12:54:21.517 | HTML conversion | How to convert HTML CSS file to wxPython files? That is, how to create slidsheet in wxPython like HTML CSS files? | stylesheet, not slidesheet.
f = open('NAMEOFSTYLESHEET.css','w')
f.write('#ID{}\n.class{}') | 0 | false | 1 | 200 |
2009-06-25 11:19:47.427 | Encrypt a string using a public key | I need to take a string in Python and encrypt it using a public key.
Can anyone give me an example or recommendation about how to go about doing this? | I looked at the ezPyCrypto library that was recommended in another answer.
Please don't use this library. It is very incomplete and in some cases incorrect and highly insecure. Public key algorithms have many pitfalls and need to be implemented carefully.
For example, RSA message should use a padding scheme such as PKCS #1, OAEP etc to be secure. This library doesn't pad. DSA signatures should use the SHA1 hash function. This library uses the broken MD5 hash and there is even a bigger bug in the random number generation. Hence the DSA implementation is neither standards conform nor secure. ElGamal is also implemented incorrectly.
Following standards does make implementations somewhat more complex. But not following any is not an option. At least not if you care about security. | 0.201295 | false | 1 | 201 |
2009-06-25 11:59:01.843 | Best Practise for transferring a MySQL table to another server? | I have a system sitting on a "Master Server", that is periodically transferring quite a few chunks of information from a MySQL DB to another server in the web.
Both servers have a MySQL Server and an Apache running. I would like an easy-to-use solution for this.
Currently I'm looking into:
XMLRPC
RestFul Services
a simple POST to a processing script
socket transfers
The app on my master is a TurboGears app, so I would prefer "pythonic" aka less ugly solutions. Copying a dumped table to another server via FTP / SCP or something like that might be quick, but in my eyes it is also very (quick and) dirty, and I'd love to have a nicer solution.
Can anyone describe shortly how you would do this the "best-practise" way?
This doesn't necessarily have to involve Databases. Dumping the table on Server1 and transferring the raw data in a structured way so server2 can process it without parsing too much is just as good. One requirement though: As soon as the data arrives on server2, I want it to be processed, so there has to be a notification of some sort when the transfer is done. Of course I could just write my whole own server sitting on a socket on the second machine and accepting the file with own code and processing it and so forth, but this is just a very very small piece of a very big system, so I dont want to spend half a day implementing this.
Thanks,
Tom | Assuming your situation allows this security-wise, you forgot one transport mechanism: simply opening a mysql connection from one server to another.
Me, I would start by thinking about one script that ran regularly on the write server and opens a read only db connection to the read server (A bit of added security) and a full connection to it's own data base server.
How you then proceed depends on the data (is it just inserts to deal with? do you have to mirror deletes? how many inserts vs updates? etc) but basically you could write a script that pulled data from the read server and processed it immediately into the write server.
Also, would mysql server replication work or would it be to over-blown as a solution? | 0 | false | 2 | 202 |
2009-06-25 11:59:01.843 | Best Practise for transferring a MySQL table to another server? | I have a system sitting on a "Master Server", that is periodically transferring quite a few chunks of information from a MySQL DB to another server in the web.
Both servers have a MySQL Server and an Apache running. I would like an easy-to-use solution for this.
Currently I'm looking into:
XMLRPC
RestFul Services
a simple POST to a processing script
socket transfers
The app on my master is a TurboGears app, so I would prefer "pythonic" aka less ugly solutions. Copying a dumped table to another server via FTP / SCP or something like that might be quick, but in my eyes it is also very (quick and) dirty, and I'd love to have a nicer solution.
Can anyone describe shortly how you would do this the "best-practise" way?
This doesn't necessarily have to involve Databases. Dumping the table on Server1 and transferring the raw data in a structured way so server2 can process it without parsing too much is just as good. One requirement though: As soon as the data arrives on server2, I want it to be processed, so there has to be a notification of some sort when the transfer is done. Of course I could just write my whole own server sitting on a socket on the second machine and accepting the file with own code and processing it and so forth, but this is just a very very small piece of a very big system, so I dont want to spend half a day implementing this.
Thanks,
Tom | Server 1: Convert rows to JSON, call the RESTful api of second with JSON data
Server 2: listens on a URI e.g. POST /data , get json data convert back to dictionary or ORM objects, insert into db
sqlalchemy/sqlobject and simplejson is what you need. | 1.2 | true | 2 | 202 |
2009-06-26 10:44:01.177 | Hiding characters typed into password field | I am developing an student attendance application in wxpython and I need to know how to ensure that password field doesn't echo characters to the screen.
Forexample :if I give the name as moni means then it should be displayed as in format of **** | You need to give your text control the TE_PASSWORD style.
(As Jørn's comment points out, this isn't "encryption" - I'm assuming you're only talking about the visual presentation of the password.) | 0.386912 | false | 1 | 203 |
2009-06-26 16:39:30.670 | Get remote text file, process, and update database - approach and scripting language to use? | I've been having to do some basic feed processing. So, get a file via ftp, process it (i.e. get the fields I care about), and then update the local database. And similarly the other direction: get data from db, create file, and upload by ftp. The scripts will be called by cron.
I think the idea would be for each type of feed, define the ftp connection/file information. Then there should be a translation of how data fields in the file relate to data fields that the application can work with (and of course process this translation). Additionally write separate scripts that do the common inserting functions for the different objects that may be used in different feeds.
As an e-commerce example, lets say I work with different suppliers who provide feeds to me. The feeds can be different (object) types: product, category, or order information. For each type of feed I obviously work with different fields and call different update or insert scripts.
What is the best language to implement this in? I can work with PHP but am looking for a project to start learning Perl or Python so this could be good for me as well.
If Perl or Python, can you briefly give high level implementation. So how to separate the different scripts, object oriented approach?, how to make it easy to implement new feeds or processing functions in the future, etc.
[full disclosure: There were already classes written in PHP which I used to create a new feed recently. I already did my job, but it was super messy and difficult to do. So this question is not 'Please help me do my job' but rather a 'best approach' type of question for my own development.]
Thanks! | Most modern languages scripting languages allow you to do all of these things. Because of that, I think your choice of language should be based on what you and the people who read your code know.
In Perl I'd make use of the following modules:
Net::FTP to access the ftp sites.
DBI to insert data into your database.
Modules like that are nice reusable pieces of code that you don't have to write, and interaction with ftp sites and databases are so common that every modern scripting language should have similar modules.
I don't think that PHP is a great language so I'd avoid it if possible, but it might make sense for you if you have a lot of experience in it. | 0.101688 | false | 1 | 204 |
2009-06-27 22:41:01.413 | Changing python interpreter windows | I have two python installations, 2.5 and 2.6
I want to change the default python interpreter from 2.5 to 2.6.
Anyone know how? | PYTHONPATH is NOT what you are looking for. That is for varying where Python's "import" looks for packages and modules.
You need to change the PATH variable in your environment so that it contains e.g. "....;c:\python26;...." instead of "....;c:\python25;....". Click on start > control panel > system > advanced > environment variables. Select "path". Edit it. Click on OK enough times to get out of there. | 1.2 | true | 2 | 205 |
2009-06-27 22:41:01.413 | Changing python interpreter windows | I have two python installations, 2.5 and 2.6
I want to change the default python interpreter from 2.5 to 2.6.
Anyone know how? | just FYI, since both c:\python25 and c:\python26 are on PATH, I copy C:\Python25\python.exe to C:\Python25\py25.exe, and copy C:\Python26\python.exe to C:\Python26\py26.exe
Then just type py25(or py26) get the specific version. | 0.201295 | false | 2 | 205 |
2009-06-30 13:14:59.567 | how to use french letters in a django template? | I have some french letters (é, è, à...) in a django template but when it is loaded by django, an UnicodeDecodeError exception is raised.
If I don't load the template but directly use a python string. It works ok.
Is there something to do to use unicode with django template? | You are probably storing the template in a non-unicode encoding, such as latin-1. I believe Django assumes that templates are in UTF-8 by default (though there is a setting to override this).
Your editor should be capable of saving the template file in the UTF-8 encoding (probably via a dropdown on the save as page, though this may depend on your editor). Re-save the file as UTF-8, and the error should go away. | 1.2 | true | 1 | 206 |
2009-06-30 13:45:12.203 | In Python, Using pyodbc, How Do You Perform Transactions? | I have a username which I must change in numerous (up to ~25) tables. (Yeah, I know.) An atomic transaction seems to be the way to go for this sort of thing. However, I do not know how to do this with pyodbc. I've seen various tutorials on atomic transactions before, but have never used them.
The setup: Windows platform, Python 2.6, pyodbc, Microsoft SQL 2005. I've used pyodbc for single SQL statements, but no compound statements or transactions.
Best practices for SQL seem to suggest that creating a stored procedure is excellent for this. My fears about doing a stored procedure are as follows, in order of increasing importance:
1) I have never written a stored procedure.
2) I heard that pyodbc does not return results from stored procedures as of yet.
3) This is most definitely Not My Database. It's vendor-supplied, vendor-updated, and so forth.
So, what's the best way to go about this? | I don't think pyodbc has any specific support for transactions. You need to send the SQL command to start/commit/rollback transactions. | -0.999909 | false | 1 | 207 |
2009-07-02 16:16:07.920 | How to debug SCons scripts using eclipse and pydev? | I'm a newbie to SCons and also using pydev. Can someone help me with instructions on how to debug scons scripts using Eclipse and pydev? Is it even possible considering the fact that SCons is a seperate app and not an extension to python? | I'm not an Eclipse expert, but since you didn't get any other answer...
If you make the SCons source a part of the Eclipse project, and run the whole command from within Eclipse it should work like any Eclipse debugging. SCons is written in Python, there is no reason it shouldn't be debuggable in Eclipse just like anything else. | 1.2 | true | 5 | 208 |
2009-07-02 16:16:07.920 | How to debug SCons scripts using eclipse and pydev? | I'm a newbie to SCons and also using pydev. Can someone help me with instructions on how to debug scons scripts using Eclipse and pydev? Is it even possible considering the fact that SCons is a seperate app and not an extension to python? | You are right. Since the SCons is python based, the SCons scripts are debuggable via EClipse PyDev. For this, you need to do the following in the debug configuration...
1. Under the main tab, set the main module to the SCons file which will be available under the python/scripts directory if you have installed SCons. If you have not run the install of SCons you can point to this file under the SCons directory.
2. Under the arguments tab, set the working directory to the root of your project.
Now set the breakpoint either on SConstruct or SConcript and run in debug mode. That's all!!
With this approach you can not only debug your product code but also the build scripts that builds your product :-) Happy Debugging!!!! | 0.386912 | false | 5 | 208 |
2009-07-02 16:16:07.920 | How to debug SCons scripts using eclipse and pydev? | I'm a newbie to SCons and also using pydev. Can someone help me with instructions on how to debug scons scripts using Eclipse and pydev? Is it even possible considering the fact that SCons is a seperate app and not an extension to python? | I've since gain more experience with SCons / Python and I'd recommend using python's pdb module. To use it simply add the following code to your SCons/Python files.
import pdb; pdb.set_trace()
When the file is run from the command line a breakpoint will be hit at this line. I also moved away from Eclipse. A lightweight editor will be just as good for Python development. I use Sublime. | 0 | false | 5 | 208 |
2009-07-02 16:16:07.920 | How to debug SCons scripts using eclipse and pydev? | I'm a newbie to SCons and also using pydev. Can someone help me with instructions on how to debug scons scripts using Eclipse and pydev? Is it even possible considering the fact that SCons is a seperate app and not an extension to python? | On MAC to debug scons through pydev follow Lennart's answer but with one simply addition.
Using Finder (or terminal) browse to where scons is installed. You can find this with the "which" command.
e.g. which scons
-> /usr/local/bin/scons
Make a copy of the scons file and call it scons.py.
Now when you create the Debug Configuration in Eclipse use scons.py as the "Main Module".
PS: To add a scons project to Eclipse I found it easier to use a "Linked Folder" pointing at /usr/local/bin/. i.e. Because I was getting a read-only error when trying to add the directory itself. | 0.067922 | false | 5 | 208 |
2009-07-02 16:16:07.920 | How to debug SCons scripts using eclipse and pydev? | I'm a newbie to SCons and also using pydev. Can someone help me with instructions on how to debug scons scripts using Eclipse and pydev? Is it even possible considering the fact that SCons is a seperate app and not an extension to python? | As an addendum: on Windows, I had to copy the scons-installed files to reside under C:\Python27\Lib\site-packages\scons in order for this to work. Adding the original installed location, qualified with the version number, to the PYTHONPATH, did not work. | 0 | false | 5 | 208 |
2009-07-03 03:24:31.120 | Windows Application Programming & wxPython | Developing a project of mine I realize I have a need for some level of persistence across sessions, for example when a user executes the application, changes some preferences and then closes the app. The next time the user executes the app, be it after a reboot or 15 minutes, I would like to be able to retain the preferences that had been changed.
My question relates to this persistence. Whether programming an application using the win32 API or the MFC Framework .. or using the newer tools for higher level languages such as wxPython or wxRuby, how does one maintain the type of persistence I refer to? Is it done as a temporary file written to the disk? Is it saved into some registry setting? Is there some other layer it is stored in that I am unaware of? | I would advice to do it in two steps.
First step is to save your prefs. as
string, for that you can
a)
Use any xml lib or output xml by
hand to output string and read
similarly from string
b) Just use pickle module to dump your prefs object as a string
c) Somehow generate a string from prefs which you can read back as prefs e.g. use yaml, config , JSON etc actually JSON is a good option when simplejson makes it so easy.
Once you have your methods to convert to and from string are ready, you just need to store it somewhere where it is persisted and you can read back next time, for that you can
a) Use wx.Config which save to registry in windows and to other places depending on platform so you don't have to worry where it saves, you can just read back values in platform independent way. But if you wish you can just use wx.Config for directly saving reading prefs.
b) Directly save prefs. string to a file in a folder assigned by OS to your app e.g. app data folder in windows.
Benefit of saving to a string and than using wx.Config to save it, is that you can easily change where data is saved in future e.g. in future if there is a need to upload prefs. you can just upload prefs. string. | 1.2 | true | 1 | 209 |
2009-07-06 03:33:04.817 | how to make table partitions? | I am not very familiar with databases, and so I do not know how to partition a table using SQLAlchemy.
Your help would be greatly appreciated. | Automatic partitioning is a very database engine specific concept and SQLAlchemy doesn't provide any generic tools to manage partitioning. Mostly because it wouldn't provide anything really useful while being another API to learn. If you want to do database level partitioning then do the CREATE TABLE statements using custom Oracle DDL statements (see Oracle documentation how to create partitioned tables and migrate data to them). You can use a partitioned table in SQLAlchemy just like you would use a normal table, you just need the table declaration so that SQLAlchemy knows what to query. You can reflect the definition from the database, or just duplicate the table declaration in SQLAlchemy code.
Very large datasets are usually time-based, with older data becoming read-only or read-mostly and queries usually only look at data from a time interval. If that describes your data, you should probably partition your data using the date field.
There's also application level partitioning, or sharding, where you use your application to split data across different database instances. This isn't all that popular in the Oracle world due to the exorbitant pricing models. If you do want to use sharding, then look at SQLAlchemy documentation and examples for that, for how SQLAlchemy can support you in that, but be aware that application level sharding will affect how you need to build your application code. | 0.386912 | false | 1 | 210 |
2009-07-07 22:55:08.403 | Matrix from Python to MATLAB | I'm working with Python and MATLAB right now and I have a 2D array in Python that I need to write to a file and then be able to read it into MATLAB as a matrix. Any ideas on how to do this?
Thanks! | I would probably use numpy.savetxt('yourfile.mat',yourarray) in Python
and then yourarray = load('yourfile.mat') in MATLAB. | 0.283556 | false | 2 | 211 |
2009-07-07 22:55:08.403 | Matrix from Python to MATLAB | I'm working with Python and MATLAB right now and I have a 2D array in Python that I need to write to a file and then be able to read it into MATLAB as a matrix. Any ideas on how to do this?
Thanks! | You could write the matrix in Python to a CSV file and read it in MATLAB using csvread. | 0.229097 | false | 2 | 211 |
2009-07-11 05:45:38.637 | List of installed fonts OS X / C | I'm trying to programatically get a list of installed fonts in C or Python. I need to be able to do this on OS X, does anyone know how? | Do you want to write a program to do it, or do you want to use a program to do it? There are many programs that list fonts, xlsfonts comes to mind. | 0.081452 | false | 1 | 212 |
2009-07-11 06:02:43.720 | How to keep an App Engine/Java app running with deaf requests from a Java/Python web cron? | App Engine allows you 30 seconds to load your application
My application takes around 30 seconds - sometimes more, sometimes less. I don't know how to fix this.
If the app is idle (does not receive a request for a while), it needs to be re-loaded.
So, to avoid the app needing to be reloaded, I want to simulate user activity by pinging the app every so often.
But there's a catch . . .
If I ping the app and it has already been unloaded by App Engine, my web request will be the first request to the app and the app will try to reload. This could take longer than 30 seconds and exceed the loading time limit.
So my idea is to ping the app but not wait for the response. I have simulated this manually by going to the site from a browser, making the request and immediately closing the browser - it seems to keep the app alive.
Any suggestions for a good way to do this in a Python or Java web cron (I'm assuming a Python solution will be simpler)? | App engine also has a new PAY feature where you can have it "always-on". Costs about $0.30 USD cents a day. Just go into your billing settings and enable it if you don't mind paying for the feature. I believe it guarantees you at least 3 instances always running.
(I didn't realize hitting a /ping url which caused an instance to spin up would cause it to exceed the 30 sec limit!) | 0.101688 | false | 1 | 213 |
2009-07-11 18:11:18.877 | How do I check if a process is alive in Python on Linux? | I have a process id in Python. I know I can kill it with os.kill(), but how do I check if it is alive ? Is there a built-in function or do I have to go to the shell? | os.kill does not kill processes, it sends them signals (it's poorly named).
If you send signal 0, you can determine whether you are allowed to send other signals. An error code will indicate whether it's a permission problem or a missing process.
See man 2 kill for more info.
Also, if the process is your child, you can get a SIGCHLD when it dies, and you can use one of the wait calls to deal with it. | 0.999823 | false | 1 | 214 |
2009-07-14 15:19:21.097 | Python: Persistent shell variables in subprocess | I'm trying to execute a series of commands using Pythons subprocess module, however I need to set shell variables with export before running them. Of course the shell doesn't seem to be persistent so when I run a command later those shell variables are lost.
Is there any way to go about this? I could create a /bin/sh process, but how would I get the exit codes of the commands run under that? | subprocess.Popen takes an optional named argument env that's a dictionary to use as the subprocess's environment (what you're describing as "shell variables"). Prepare a dict as you need it (you may start with a copy of os.environ and alter that as you need) and pass it to all the subprocess.Popen calls you perform. | 1.2 | true | 1 | 215 |
2009-07-14 17:28:02.430 | Best way to have full Python install under cygwin/XP? | Pythons installed under WinXP have dirs like DLLs, DOC, include, etc. but python (2.5) installed with cygwin is a bare python.exe. My motivation for asking is that 'things' under XP don't seem to be finding 'other things' under cygwin and vice versa, I want to start developing with Qt, I like shells, and I do not like MS; I thought if I got all the components under one roof, I could finally start to have scripts find executables which could find files and such. 1. Can I simply copy the contents of an XP installation into the cygwin tree? 2. Is the XP flavor of Python different from the cygwin flavor? (Same CPU, he pointed out, naively.) 3. Someone must work with a full-fledged (if snakes had feathers...) Python from within cygwin; how is it done?
Disclaimer 1: I have never compiled anything under XP or cygwin; had hoped not to have to go there, hence, python in the first place. Disclaimer 2: sorry if this is a ServerFault question, but they seemed to be system people over there and this is (in my case) a lowly desktop. | Just a little off the question, but...
Have you considered running Sun's VirtualBox with Fedora or Ubuntu inside of it? I'm assuming you have to / need to use windows because you still are, but don't like it. Then you would have python running inside a native linux desktop without any of the troubles you mentioned.
And if you want something that is really easy and portable, then just use Python on Windows, not mixed in with cygwin.
$0.02 | 0 | false | 4 | 216 |
2009-07-14 17:28:02.430 | Best way to have full Python install under cygwin/XP? | Pythons installed under WinXP have dirs like DLLs, DOC, include, etc. but python (2.5) installed with cygwin is a bare python.exe. My motivation for asking is that 'things' under XP don't seem to be finding 'other things' under cygwin and vice versa, I want to start developing with Qt, I like shells, and I do not like MS; I thought if I got all the components under one roof, I could finally start to have scripts find executables which could find files and such. 1. Can I simply copy the contents of an XP installation into the cygwin tree? 2. Is the XP flavor of Python different from the cygwin flavor? (Same CPU, he pointed out, naively.) 3. Someone must work with a full-fledged (if snakes had feathers...) Python from within cygwin; how is it done?
Disclaimer 1: I have never compiled anything under XP or cygwin; had hoped not to have to go there, hence, python in the first place. Disclaimer 2: sorry if this is a ServerFault question, but they seemed to be system people over there and this is (in my case) a lowly desktop. | I use Python from within cygwin, but I don't use the version that cygwin gives you the option of installing as I don't have the control over version number used that I need (we use an older version at work). I have my python version installed via the windows installer (the xp version as you put it) and add the /cygdrive/c/Python2x directory to my PATH environment variable. | 1.2 | true | 4 | 216 |
2009-07-14 17:28:02.430 | Best way to have full Python install under cygwin/XP? | Pythons installed under WinXP have dirs like DLLs, DOC, include, etc. but python (2.5) installed with cygwin is a bare python.exe. My motivation for asking is that 'things' under XP don't seem to be finding 'other things' under cygwin and vice versa, I want to start developing with Qt, I like shells, and I do not like MS; I thought if I got all the components under one roof, I could finally start to have scripts find executables which could find files and such. 1. Can I simply copy the contents of an XP installation into the cygwin tree? 2. Is the XP flavor of Python different from the cygwin flavor? (Same CPU, he pointed out, naively.) 3. Someone must work with a full-fledged (if snakes had feathers...) Python from within cygwin; how is it done?
Disclaimer 1: I have never compiled anything under XP or cygwin; had hoped not to have to go there, hence, python in the first place. Disclaimer 2: sorry if this is a ServerFault question, but they seemed to be system people over there and this is (in my case) a lowly desktop. | I accidentally stumbled on this - If I launch Cygwin from the Cygwin.bat file (which is present directly under the main folder), I get access to the Python version installed under Cygwin (i.e 2.6.8)
If I instead launch the Cygwin from bash.exe under bin directory (C:\Cygwin\bin\bash.exe for me), running "Python -V" shows that I have access to 2.7.3 version of Python (that was installed for Windows).
So, I guess you can do the same. | 0 | false | 4 | 216 |
2009-07-14 17:28:02.430 | Best way to have full Python install under cygwin/XP? | Pythons installed under WinXP have dirs like DLLs, DOC, include, etc. but python (2.5) installed with cygwin is a bare python.exe. My motivation for asking is that 'things' under XP don't seem to be finding 'other things' under cygwin and vice versa, I want to start developing with Qt, I like shells, and I do not like MS; I thought if I got all the components under one roof, I could finally start to have scripts find executables which could find files and such. 1. Can I simply copy the contents of an XP installation into the cygwin tree? 2. Is the XP flavor of Python different from the cygwin flavor? (Same CPU, he pointed out, naively.) 3. Someone must work with a full-fledged (if snakes had feathers...) Python from within cygwin; how is it done?
Disclaimer 1: I have never compiled anything under XP or cygwin; had hoped not to have to go there, hence, python in the first place. Disclaimer 2: sorry if this is a ServerFault question, but they seemed to be system people over there and this is (in my case) a lowly desktop. | This probably has little value, but... I found myself in this exact situation -- we use ActivePython2.5 in production (pure windows environment) and I was trying to do my development within cygwin and cygwin's Python...
After ripping out half of my hair, I have now switched over to Console2, gvim, iPython and ActivePython2.5.
I'm less than thrilled dealing with Windows tools (and their concomitant warts), but at least I'm not getting in my own way when it comes to development. For a while I found I was spending more time trying to get my tools to play nice than actually getting any work done.
Good luck on this one. | 0 | false | 4 | 216 |