Q_Id int64 337 49.3M | CreationDate stringlengths 23 23 | Users Score int64 -42 1.15k | Other int64 0 1 | Python Basics and Environment int64 0 1 | System Administration and DevOps int64 0 1 | Tags stringlengths 6 105 | A_Id int64 518 72.5M | AnswerCount int64 1 64 | is_accepted bool 2
classes | Web Development int64 0 1 | GUI and Desktop Applications int64 0 1 | Answer stringlengths 6 11.6k | Available Count int64 1 31 | Q_Score int64 0 6.79k | Data Science and Machine Learning int64 0 1 | Question stringlengths 15 29k | Title stringlengths 11 150 | Score float64 -1 1.2 | Database and SQL int64 0 1 | Networking and APIs int64 0 1 | ViewCount int64 8 6.81M |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
4,415,649 | 2010-12-11T07:05:00.000 | 1 | 0 | 0 | 0 | python | 4,415,722 | 2 | false | 0 | 1 | If you're looking for a way to do it with just the standard Python library, the answer is probably "no" - or at the very least, "not in any straightforward manner". There are many things in the standard library, but gaming hardware support is not one of them. | 1 | 1 | 0 | Is there anyway I could register button pushes on a joystick without using any function from pygame? | Detecting an arbittrary button press on a USB joystick WITHOUT pygame | 0.099668 | 0 | 0 | 916 |
4,416,570 | 2010-12-11T11:50:00.000 | 3 | 0 | 0 | 0 | python,webkit,gtk | 4,421,093 | 2 | true | 1 | 1 | You can't. webview.load_uri() takes a string containing a URI. 'file.html' isn't a URI, 'file://file.html' is. | 2 | 2 | 0 | Every time I need to load a local file using webkit in python I need to start with "file://" which I need to include in all files I am working with. How can I eliminate the need to do that? I want to load files like webview.load_uri('file.html') instead of webview.load_uri('file://file.html')? | Problem loading local files with webkit in python | 1.2 | 0 | 0 | 2,182 |
4,416,570 | 2010-12-11T11:50:00.000 | 1 | 0 | 0 | 0 | python,webkit,gtk | 7,470,386 | 2 | false | 1 | 1 | webview.load_string() takes the text of an html file. you can load the file into a file object without the file:// and read it into the load_string function. | 2 | 2 | 0 | Every time I need to load a local file using webkit in python I need to start with "file://" which I need to include in all files I am working with. How can I eliminate the need to do that? I want to load files like webview.load_uri('file.html') instead of webview.load_uri('file://file.html')? | Problem loading local files with webkit in python | 0.099668 | 0 | 0 | 2,182 |
4,416,642 | 2010-12-11T12:17:00.000 | -1 | 0 | 1 | 0 | python,shell | 67,948,618 | 5 | false | 0 | 0 | You can,,go to options then configure IDE, then on the settings window select highlights, on the rightside press the button below a builtin theme, then choose your choice theme | 3 | 4 | 0 | Is it possible to change background color of the Python Shell from white to black for example. I did find how to change text color, but can't figure out how to change background color. I'm running it under the Windows. Any suggestions? | Change background color of python shell | -0.039979 | 0 | 0 | 86,168 |
4,416,642 | 2010-12-11T12:17:00.000 | 2 | 0 | 1 | 0 | python,shell | 4,417,082 | 5 | false | 0 | 0 | If you are reffering to the window idle for example for version 2.6 there is now way to change the background color from withe to another one. But you can change the background color of your text if you go to options.
Another thing you can do is to use other gui for python which could be more elaborated such as eclipse pydev or to use a text editor you like and configure it the way you want to write your scripts and then run them into the idle. | 3 | 4 | 0 | Is it possible to change background color of the Python Shell from white to black for example. I did find how to change text color, but can't figure out how to change background color. I'm running it under the Windows. Any suggestions? | Change background color of python shell | 0.07983 | 0 | 0 | 86,168 |
4,416,642 | 2010-12-11T12:17:00.000 | 2 | 0 | 1 | 0 | python,shell | 17,314,925 | 5 | false | 0 | 0 | just go through simple steps
- go to options
- configure IDLE
- highlighting
- then select background and click on choose color for:
- you can change the color to any color but becareful if u change only the background color the foreground color may not be visible because they both might be black
Enjoy | 3 | 4 | 0 | Is it possible to change background color of the Python Shell from white to black for example. I did find how to change text color, but can't figure out how to change background color. I'm running it under the Windows. Any suggestions? | Change background color of python shell | 0.07983 | 0 | 0 | 86,168 |
4,416,984 | 2010-12-11T13:40:00.000 | 3 | 0 | 0 | 1 | python,macos,installation,easy-install | 4,416,999 | 4 | false | 0 | 0 | You should use sudo . You will need to enter your password. | 2 | 17 | 0 | I'm trying to install easy_install and, well... see for yourself:
sh setuptools-0.6c11-py2.6.egg
Processing setuptools-0.6c11-py2.6.egg
Copying setuptools-0.6c11-py2.6.egg to /Library/Python/2.6/site-packages
Adding setuptools 0.6c11 to easy-install.pth file
Installing easy_install script to /usr/local/bin
error: /usr/local/bin/easy_install: Permission denied
How do I give my computer permission to do this? I tried telling it in a friendly voice, "computer, I hereby grant you permission to install easy_install" but that didn't work. | Permission denied when trying to install easy_install on OSX | 0.148885 | 0 | 0 | 17,459 |
4,416,984 | 2010-12-11T13:40:00.000 | 3 | 0 | 0 | 1 | python,macos,installation,easy-install | 4,417,579 | 4 | false | 0 | 0 | Judging from the paths displayed, you are likely using the Apple-supplied Python 2.6 in OS X 10.6. If so, be aware that Apple has already easily installed easy_install for you in /usr/bin. Just try typing easy_install; you may need to use sudo easy_install if the package tries to install a script. If you are using another Python (one you installed yourself), you will need to install a separate version of setuptools (or the newer Distribute) for it. | 2 | 17 | 0 | I'm trying to install easy_install and, well... see for yourself:
sh setuptools-0.6c11-py2.6.egg
Processing setuptools-0.6c11-py2.6.egg
Copying setuptools-0.6c11-py2.6.egg to /Library/Python/2.6/site-packages
Adding setuptools 0.6c11 to easy-install.pth file
Installing easy_install script to /usr/local/bin
error: /usr/local/bin/easy_install: Permission denied
How do I give my computer permission to do this? I tried telling it in a friendly voice, "computer, I hereby grant you permission to install easy_install" but that didn't work. | Permission denied when trying to install easy_install on OSX | 0.148885 | 0 | 0 | 17,459 |
4,417,127 | 2010-12-11T14:13:00.000 | 7 | 0 | 0 | 0 | python,django,django-templates,django-template-filters | 4,417,129 | 1 | true | 1 | 0 | The answer is maddeningly simple: split the custom tag and custom filter into two separate python files and it will work.
I suspect the problem is this: the custom tag is using template.loader.get_template() to load another template. That template file contains a {% load %} tag which tries to load the same file in which the parent custom tag is defined. For some reason, this doesn't work-- perhaps because it would cause an infinite loop or because Django assumes it's already loaded.
I didn't try recusrively loading a custom tag inside a filter, or a tag inside another tag, to see if the same problem occurs there too, but if it does, the fix would be the same: if you want to use template.loader.get_template() to load a template which contains calls to your own custom tags or filters, make sure that the file calling template.loader.get_template() is a different file from the file defining your included tags/filers. | 1 | 1 | 0 | I have a python file in my Django project which contains a custom template tag and a custom template filter.
My custom tag uses template.loader.get_template() to load another template file. This worked great... until I added my custom filter to the loaded template.
Now I get a Django "Invalid Filter" TemplateSyntaxError exception. Looking at the call stack, Django is unable to load my template filter.
Here's where things get weird. I can use my custom filters from another template. I can use any other filter inside the template loaded by my custom tag. But I can't use my own filter inside my own custom tag.
The obvious cause of this would be not loading my custom tag/filter file inside my template HTML, but I am correctly loading it. (because when I don't load it, I'll get a different error -- "invalid block tag")
I'm running Django 1.2.3 on Python 2.7.
[BTW, I finally found the answer myself, but it took me several hours and I wasn't able to find the answer anywhere on stackoverflow or google, so I'm going to answer my own question so others won't have to waste as much time as I did] | "Invalid Filter" error for my custom Django template filters but not any other filters | 1.2 | 0 | 0 | 6,013 |
4,417,316 | 2010-12-11T15:02:00.000 | 1 | 0 | 1 | 0 | python,compiler-construction | 4,417,403 | 6 | false | 0 | 0 | py2exe - Python to Windows EXE
py2exe converts your Python programs to standalone Windows executables that can run without your users needing to install Python. Note that this is not a native code compiler - your code is still interpreted. py2exe merely provides all the necessary pieces so that when your end users double-click on your executable, the Python interpreter will start up to interpret your code. py2exe is released under the Mozilla Public License | 3 | 0 | 0 | Ok so i am in need of a python compiler (from .py or .pyw to .exe).
the only ones i have come across are:
- cx_freeze (doesnt work)
- py2exe (way too complicated)
EDIT:
both of the programs above are complicated (to me) because you have to make all these setup files, and type in a bunch of parameters and commands to get them to work,i found something called gui2exe.py however i cant seem to get it to load correctly... any thoughts?
So what i was looking for was a program that you do not have to run through the python command line. Prefereably a stand alone program, that you can just select the file and select the output (.exe) and click convert. Nothing too complicated as i am just starting out.
The reason i want this is because i have a program that my friend wanted to take a look at but he doesnt want to download python in order to view it. Also i dont want him to be able to change the source code.
Any Ideas? | I need a stand alone python interpreter/compiler! | 0.033321 | 0 | 0 | 4,305 |
4,417,316 | 2010-12-11T15:02:00.000 | 0 | 0 | 1 | 0 | python,compiler-construction | 4,419,301 | 6 | false | 0 | 0 | You could also simply provide your friend a ZIP file containing python.exe, the python libs, and your python application (in pyc) along with a batch to start python.exe with your script. Python is fairly easy to run without it being 'installed'. | 3 | 0 | 0 | Ok so i am in need of a python compiler (from .py or .pyw to .exe).
the only ones i have come across are:
- cx_freeze (doesnt work)
- py2exe (way too complicated)
EDIT:
both of the programs above are complicated (to me) because you have to make all these setup files, and type in a bunch of parameters and commands to get them to work,i found something called gui2exe.py however i cant seem to get it to load correctly... any thoughts?
So what i was looking for was a program that you do not have to run through the python command line. Prefereably a stand alone program, that you can just select the file and select the output (.exe) and click convert. Nothing too complicated as i am just starting out.
The reason i want this is because i have a program that my friend wanted to take a look at but he doesnt want to download python in order to view it. Also i dont want him to be able to change the source code.
Any Ideas? | I need a stand alone python interpreter/compiler! | 0 | 0 | 0 | 4,305 |
4,417,316 | 2010-12-11T15:02:00.000 | 2 | 0 | 1 | 0 | python,compiler-construction | 4,417,435 | 6 | false | 0 | 0 | One option might be to use IronPython. IronPython is another dialect of python that targets .NET, and works quite easily with MS Visual Studio. | 3 | 0 | 0 | Ok so i am in need of a python compiler (from .py or .pyw to .exe).
the only ones i have come across are:
- cx_freeze (doesnt work)
- py2exe (way too complicated)
EDIT:
both of the programs above are complicated (to me) because you have to make all these setup files, and type in a bunch of parameters and commands to get them to work,i found something called gui2exe.py however i cant seem to get it to load correctly... any thoughts?
So what i was looking for was a program that you do not have to run through the python command line. Prefereably a stand alone program, that you can just select the file and select the output (.exe) and click convert. Nothing too complicated as i am just starting out.
The reason i want this is because i have a program that my friend wanted to take a look at but he doesnt want to download python in order to view it. Also i dont want him to be able to change the source code.
Any Ideas? | I need a stand alone python interpreter/compiler! | 0.066568 | 0 | 0 | 4,305 |
4,418,252 | 2010-12-11T18:30:00.000 | 1 | 0 | 0 | 1 | python,syntax,batch-file,equivalent | 4,418,349 | 5 | false | 0 | 0 | Python is not a system shell, Python is a multi-paradigm programming language.
If you want to compare .bat with anything, compare it with sh or bash. (You can have those on various platforms too - for example, sh for windows is in the MinGW package). | 2 | 1 | 0 | Ok i have these commands used in batch and i wanted to know the commands in python that would have a similar affect, just to be clear i dont want to just use os.system("command here") for each of them. For example in batch if you wanted a list of commands you would type help but in python you would type help() and then modules... I am not trying to use batch in a python script, i just wanna know the similarities in both languages. Like in english you say " Hello" but in french you say "Bonjour" not mix the two languages. (heres the list of commands/functions id like to know:
change the current directory
clear the screen in the console
change the prompt to something other than >>>
how to make a loop function
redirections/pipes
start an exteral program (like notepad or paint) from within a script
how to call or import another python script
how to get help with a specific module without having to type help()
@8: (in batch it would be command /?)
EDITED COMPLETELY
Thanks in Adnvance! | comparing batch to python commands? | 0.039979 | 0 | 0 | 2,645 |
4,418,252 | 2010-12-11T18:30:00.000 | 0 | 0 | 0 | 1 | python,syntax,batch-file,equivalent | 17,412,938 | 5 | false | 0 | 0 | I am pretty much facing the same problem as you, daniel11. As a solution, I am learning BATCH commands and their meaning. After I understand those, I am going to write a program in Python that does the same or accomplishes the same task.
Thanks to Adam V. and katrielatex for their insight and suggestions. | 2 | 1 | 0 | Ok i have these commands used in batch and i wanted to know the commands in python that would have a similar affect, just to be clear i dont want to just use os.system("command here") for each of them. For example in batch if you wanted a list of commands you would type help but in python you would type help() and then modules... I am not trying to use batch in a python script, i just wanna know the similarities in both languages. Like in english you say " Hello" but in french you say "Bonjour" not mix the two languages. (heres the list of commands/functions id like to know:
change the current directory
clear the screen in the console
change the prompt to something other than >>>
how to make a loop function
redirections/pipes
start an exteral program (like notepad or paint) from within a script
how to call or import another python script
how to get help with a specific module without having to type help()
@8: (in batch it would be command /?)
EDITED COMPLETELY
Thanks in Adnvance! | comparing batch to python commands? | 0 | 0 | 0 | 2,645 |
4,418,378 | 2010-12-11T19:00:00.000 | -2 | 1 | 1 | 1 | python,linux,bash | 4,420,885 | 4 | false | 0 | 0 | There is no direct way you can do it .
But you can make a python script to emulate a bash terminal and you can use the beautiful "Subprocess" module in python to execute commnands the way you like | 1 | 12 | 0 | What i'd like to have is a mechanism that all commands i enter on a Bash-Terminal are wrapped by a Python-script. The Python-script executes the entered command, but it adds some additional magic (for example setting "dynamic" environment variables).
Is that possible somehow?
I'm running Ubuntu and Debian Squeezy.
Additional explanation:
I have a property-file which changes dynamically (some scripts do alter it at any time). I need the properties from that file as environment variables in all my shell scripts. Of course i could parse the property-file somehow from shell, but i prefer using an object-oriented style for that (especially for writing), as it can be done with Python (and ConfigObject).
Therefore i want to wrap all my scripts with that Python script (without having to modify the scripts themselves) which handles these properties down to all Shell-scripts.
This is my current use case, but i can imagine that i'll find additional cases to which i can extend my wrapper later on. | Wrap all commands entered within a Bash-Shell with a Python script | -0.099668 | 0 | 0 | 3,793 |
4,418,461 | 2010-12-11T19:17:00.000 | 2 | 0 | 0 | 0 | python,django,database-design | 4,418,851 | 2 | true | 1 | 0 | Editors often solve this problem with a Piece Table. The table is a list of objects that point to spans of characters that are a) contiguous in memory, and b) share common attributes. The order of the pieces in the table is used for mapping character-in-document addresses to memory and vice versa. By reordering the piece table you effectively reorder the document without moving anything around. The key point is that the piece table itself is independent of the objects that make up the content of the document.
So one way of mapping your paragraph order would be to have a simplified version of a peice table. This could be as simple as a list of para-ids in document order. When you need to change something, you fetch the list, unpickle it, make you edits on the list, pickle and save.
Another advantage of the table is that it greatly simplifies implementing undo. The history file is a simple list of edits to the table, and undoing/redoing is a matter of reversing or reapplying a particular edit to the table, the data itself doesn't change. This should play well with any versioning you want to do. | 1 | 1 | 0 | I'm having trouble figuring out how to best implement a document (paragraph-) revision system in Django.
I want to save a revision history of a document, paragraph-by-paragraph. In other words, there will be a class Document, which has a ManyToManyField to Paragraph. To maintain the order of the paragraphs, a third class ParagraphContainer can be created.
My question is, what is a good way to implement this in Django so that the order of paragraphs is maintained when someone adds a new paragraph in-between existing paragraphs?
One obvious way would be to have a position attribute in the ParagraphContainer class, but then this field will have to be updated in all paragraphs following the inserted (or deleted) paragraph. A linked list is another option, but I'm scared that might be very slow for retrieval of the whole document. Any advice? | How to maintain order of paragraphs in a Django document revision system? | 1.2 | 0 | 0 | 304 |
4,418,839 | 2010-12-11T20:40:00.000 | 1 | 0 | 0 | 0 | python,wing-ide | 4,431,943 | 1 | true | 0 | 1 | I've contacted Wingware support and they have confirmed that there is no way to set the brace matching colour. | 1 | 3 | 0 | Has anyone figured out a way to change the brace matching colours in WingIDE? I have managed to manually port my favourite colour scheme across from my text editor and the default green just doesn't do it for me. I've been unable to find instructions on how to do this in the UI, user manual and mailing lists. | WingIDE brace matching colours | 1.2 | 0 | 0 | 135 |
4,418,931 | 2010-12-11T21:03:00.000 | 0 | 0 | 1 | 0 | python,unicode,encoding,utf-8 | 4,418,961 | 4 | false | 0 | 0 | Well, if you have a stream of bytes that are UTF-8-encoded text and you interpret them as a string encoded in something else and then re-encoding it as UTF-8, then you have a problem.
If you read it as UTF-8 again (since you cannot treat bytes as text without an encoding, certainly), then you have Unicode, which, when written as UTF-8 again will look the same as before.
Just be careful not to mess around with the encodings too much. A common error is to interpret UTF-8 encoded text as Latin 1, thereby turning Fööbär into Fööbär which then of course won't change anymore again.
Note the difference between text (the actual thing you care about) and the encoded text which is just a bunch of bytes and the knowledge how to turn them into text again. If you treat the latter as the former, problems arise. If you convert properly from one representation to the other, it's fine. | 2 | 1 | 0 | Is there any harm to encoding a string multiple times in python, with the same encoding format? (i.e, UTF-8)?
I have a function that uses another function to get a string from a document, and then serialize the string. Currently, the only user of the second function(the one which gets the string from the document) is the first function.
This might change in the future, and someone might decide to use it in another serialization (or such) function, without encoding its result to UTF-8 first. I'm wondering if its safe to always return a UTF-8 encoded string from it (this string will also be re-.encode()'d by the serialization function, at the moment). My testing indicates this isn't a problem, but, I figured I'd ask.
Thank you! | Is there any harm to encoding (with the same encoding format) a string multiple times? (in Python) | 0 | 0 | 0 | 618 |
4,418,931 | 2010-12-11T21:03:00.000 | 1 | 0 | 1 | 0 | python,unicode,encoding,utf-8 | 4,419,163 | 4 | false | 0 | 0 | In general, you should only call encode on unicode objects and only call decode on string objects.
encode encodes a Unicode object into a given encoding (stored as a string). decode decodes a given encoding back into a Unicode object.
The existance of string.encode and unicode.decode in 2.x should be treated as a historical artifact. | 2 | 1 | 0 | Is there any harm to encoding a string multiple times in python, with the same encoding format? (i.e, UTF-8)?
I have a function that uses another function to get a string from a document, and then serialize the string. Currently, the only user of the second function(the one which gets the string from the document) is the first function.
This might change in the future, and someone might decide to use it in another serialization (or such) function, without encoding its result to UTF-8 first. I'm wondering if its safe to always return a UTF-8 encoded string from it (this string will also be re-.encode()'d by the serialization function, at the moment). My testing indicates this isn't a problem, but, I figured I'd ask.
Thank you! | Is there any harm to encoding (with the same encoding format) a string multiple times? (in Python) | 0.049958 | 0 | 0 | 618 |
4,420,706 | 2010-12-12T07:29:00.000 | 4 | 0 | 1 | 0 | python,pip,virtualenv,requirements.txt | 4,424,968 | 1 | true | 0 | 0 | I figured out what the cause of my pip problems was. Long story short, source left over in the virtualenv's build directory was causing an error that made packages upgrades fail. What I actually should have been doing was clearing out that directory (which pip doesn't always do I guess) before running the pip install and it seems to do everything I want after when paired with the --upgrade/-U flag. | 1 | 2 | 0 | I feel like there must be a way to do this, but for the life of me I can't figure out how: I want to run pip against a requirements file in a virtualenv so that no matter what packages are in the virtualenv before I run pip, the requirements file is totally fulfilled (including specific versions) after I run it.
The problem now is that if I have an older version of a package installed in the virtualenv than is listed in the requirements file, it complains about the version mismatch and exits (it should just update the package to the given version). The command I'm running is pip install -I -r requirements.txt and according to pip's help, -I is supposed to make pip "Ignore the installed packages (reinstalling instead)" but it definitely isn't doing that.
What am I missing?
(It'd be nice if pip skipped the packages that are already fulfilled too.) | How can I get pip install's -I flag to work with a requirements file? | 1.2 | 0 | 0 | 3,818 |
4,422,754 | 2010-12-12T16:52:00.000 | 1 | 0 | 0 | 1 | python,django,google-app-engine,templates,adsense | 4,426,058 | 2 | false | 1 | 0 | adsense is javascript, if your django is returning nothing check your HttpResponse and how you are generating the template. it looks like you need to specify in settings.py the location of the template file.
you may want add the following (in settings.py):
import os
ROOT_PATH = os.path.dirname(__file__)
TEMPLATE_DIRS = (
os.path.join(ROOT_PATH, 'templates')
)
then put your django templates in a sub-directory to your project called "/templates"
or try the process of elimination:
comment out any javascript and see if you can generate the template from django. | 2 | 0 | 0 | I have a problem with Django on Google App Engine. I finished to design html templet for my web application and I imported them on django using django template system.
The problem is google ad-sense. I can say ad-sense banner on the html version of my pages if i try to open them in my browser. But nothing appear if I try to do the same operation with them loaded in django.
I also tried to develop a simple html template that contains only the adSense script, if i load this on django it returns a white page. No banner, nothing.
What can i do to solve this problem? | Django + Adsense on Google App Engine | 0.099668 | 0 | 0 | 1,724 |
4,422,754 | 2010-12-12T16:52:00.000 | 0 | 0 | 0 | 1 | python,django,google-app-engine,templates,adsense | 4,448,211 | 2 | false | 1 | 0 | I solved the problem! Sorry, I accidentally added some character with erroneous codeing. | 2 | 0 | 0 | I have a problem with Django on Google App Engine. I finished to design html templet for my web application and I imported them on django using django template system.
The problem is google ad-sense. I can say ad-sense banner on the html version of my pages if i try to open them in my browser. But nothing appear if I try to do the same operation with them loaded in django.
I also tried to develop a simple html template that contains only the adSense script, if i load this on django it returns a white page. No banner, nothing.
What can i do to solve this problem? | Django + Adsense on Google App Engine | 0 | 0 | 0 | 1,724 |
4,422,948 | 2010-12-12T17:35:00.000 | -1 | 0 | 1 | 0 | python,irc | 4,422,957 | 5 | false | 0 | 0 | if "Greg" in greet:
doSomething("Hi Greg")
the key is that strings take the in operator | 1 | 2 | 0 | I was wondering how to go about finding a string you don't know what is, in a string. I am writing an IRC bot and i need this function. I want to be able to write:
!greet Greg
and then my bot is supposed to say "Hi, Greg!". So what comes after greet is variable. And if i wrote !greet Matthew it would say "Hi, Matthew!".
Is this possible?
Thanks a lot.
Andesay | How to find x in a string in Python | -0.039979 | 0 | 1 | 361 |
4,425,137 | 2010-12-13T01:18:00.000 | 0 | 0 | 0 | 0 | python,pylons | 4,464,437 | 2 | false | 0 | 0 | a __before__ method is a right place to do it. | 2 | 2 | 0 | I'm writing a pylons application, and I'm wondering if there is a best practice for where to set some application specific values of the template context object (tmpl_context)?
Currently, I've added a __before__() method to the BaseController and am setting up the tmpl_context object with values there but am wondering if there is another place. | Best practice for pylons app global tmpl_context settings? | 0 | 0 | 0 | 423 |
4,425,137 | 2010-12-13T01:18:00.000 | 0 | 0 | 0 | 0 | python,pylons | 4,444,729 | 2 | false | 0 | 0 | I think the BaseController is a good place to put that, either in __call__() or in __before__(). | 2 | 2 | 0 | I'm writing a pylons application, and I'm wondering if there is a best practice for where to set some application specific values of the template context object (tmpl_context)?
Currently, I've added a __before__() method to the BaseController and am setting up the tmpl_context object with values there but am wondering if there is another place. | Best practice for pylons app global tmpl_context settings? | 0 | 0 | 0 | 423 |
4,426,002 | 2010-12-13T05:17:00.000 | 3 | 0 | 1 | 0 | python,conventions | 4,426,033 | 2 | true | 0 | 0 | No, there's no convention for organization of functions and classes. However, there are some basic guidelines that will make your source flow better and make more sense to readers:
Document. Whatever you do, make sure that the uses (and in some cases, implementation) of classes and functions is described in plain english)
Group together things that are alike. Two functions that perform similar functions? Put them together.
Use common sense. If a class extends another, the base class should come first. If a function takes an instance of a class you defined, make sure the class definition comes first.
For examples on how this is done, look no further than the Python standard library. The source files from some of the modules should give you an idea how source is organized in Python. | 1 | 6 | 0 | I'm starting a new Python project, and want to follow standard conventions as closely as possible. I've read that import statements should come first, for example. But I haven't found any conventions for things like putting all function definitions before or after all class definitions. Are there any conventions for things like this? Or does everyone typically just organize things like function and class definitions in whatever order seems to make sense? | Python source file organization | 1.2 | 0 | 0 | 2,189 |
4,426,397 | 2010-12-13T06:47:00.000 | 4 | 0 | 1 | 0 | python,string | 4,426,424 | 6 | false | 0 | 0 | "hello"[:-3] - first length - 3 characters.
"hello"[:2] - first 2 characters. | 4 | 4 | 0 | I have a string in python and I'd like to take off the last three characters. How do I go about this?
So turn something like 'hello' to 'he'. | String Manipulation in Python | 0.132549 | 0 | 0 | 17,814 |
4,426,397 | 2010-12-13T06:47:00.000 | 1 | 0 | 1 | 0 | python,string | 4,426,420 | 6 | false | 0 | 0 | type "hello"[:2]
or "hello"[:-3] which is the answer for removing the last three letters
hope this helps | 4 | 4 | 0 | I have a string in python and I'd like to take off the last three characters. How do I go about this?
So turn something like 'hello' to 'he'. | String Manipulation in Python | 0.033321 | 0 | 0 | 17,814 |
4,426,397 | 2010-12-13T06:47:00.000 | 0 | 0 | 1 | 0 | python,string | 7,232,632 | 6 | false | 0 | 0 | "hello"[:2] is the easiest way to do this however the accurate answer for the problem
would be as Saif al Harthi stated. "hello"[:-3] | 4 | 4 | 0 | I have a string in python and I'd like to take off the last three characters. How do I go about this?
So turn something like 'hello' to 'he'. | String Manipulation in Python | 0 | 0 | 0 | 17,814 |
4,426,397 | 2010-12-13T06:47:00.000 | -2 | 0 | 1 | 0 | python,string | 25,325,614 | 6 | false | 0 | 0 | if x is your string then you can use x[:len(x)-3:+1] to get the desired result | 4 | 4 | 0 | I have a string in python and I'd like to take off the last three characters. How do I go about this?
So turn something like 'hello' to 'he'. | String Manipulation in Python | -0.066568 | 0 | 0 | 17,814 |
4,426,808 | 2010-12-13T07:57:00.000 | 0 | 0 | 0 | 0 | python,django,ant,intellij-idea | 4,428,911 | 1 | false | 1 | 0 | Which module type have you created? Please try to create a regular Java module with a Java SDK, and to add a Python facet to it. | 1 | 0 | 0 | Greetings! Intellij IDEA 10 + Python plugin when creating a project using Django, does not run Apache Ant-scripts. When I try to add an Ant-script error occurs «Cannot Add Files». I can’t understand reason of problem. | Intellij IDEA 10 + Python + Django does not run Apache Ant-scripts | 0 | 0 | 0 | 679 |
4,427,623 | 2010-12-13T09:56:00.000 | 0 | 0 | 1 | 0 | python,symbian,s60,pys60 | 5,888,625 | 1 | false | 1 | 0 | I don't thinks those libraries will run on PyS60 if they are not designed for that platform. | 1 | 0 | 0 | I have Python installed on my S60 phone...but I require some addtional libraries like pyaudio and lightblue to be installed on my phone...is there a way I can do this?
Also where are the Python libraries installed on my phone? | Extra Python libraries on phone | 0 | 0 | 0 | 157 |
4,427,936 | 2010-12-13T10:36:00.000 | 0 | 0 | 0 | 0 | python,logging,file-locking | 4,427,958 | 2 | false | 0 | 0 | As far as I know, Windows does not support file locking. In other words, applications that don't know about your file being locked can't be prevented from reading a file.
But the remaining question is: how can Excel accomplish this?
You might want to try to write to a temporary file first (one that Excel does not know about) and replace the original file by it lateron. | 1 | 1 | 0 | I am writing a Python logger script which writes to a CSV file in the following manner:
Open the file
Append data
Close the file (I think this is necessary to save the changes, to be safe after every logging routine.)
PROBLEM:
The file is very much accessible through Windows Explorer (I'm using XP). If the file is opened in Excel, access to it is locked by Excel. When the script tries to append data, obviously it fails, then it aborts altogether.
OBJECTIVE:
Is there a way to lock a file using Python so that any access to it remains exclusive to the script? Or perhaps my methodology is poor in the first place? | Prevent a file from being opened | 0 | 1 | 0 | 2,562 |
4,427,981 | 2010-12-13T10:42:00.000 | 5 | 0 | 1 | 0 | python,dictionary | 4,428,010 | 5 | false | 0 | 0 | A dictionary has no order. So your wording "b's key is smaller than d's" is the right one.
Now, it looks like you could swap keys and values... | 2 | 0 | 0 | There is a dictionary that may include keys starting from 0 and values: a, b, c, d, e. Each time the values may be assigned to different keys keys. Size of the dictionary may change as well.
I am interested in two values. Let's call them b and d.
Is there any algorithm that determine situations when b appears earlier than d (i.e. b's key is smaller than d's) and when d appears earlier than b (i.e. d's key is is smaller than b's)? | Determine position of values in dictionary, Python | 0.197375 | 0 | 0 | 5,837 |
4,427,981 | 2010-12-13T10:42:00.000 | 0 | 0 | 1 | 0 | python,dictionary | 4,428,033 | 5 | false | 0 | 0 | Dictionaries are unordered sets of key-value pairs. dict.keys() need not produce the same output always. Can't you do what you want with lists? | 2 | 0 | 0 | There is a dictionary that may include keys starting from 0 and values: a, b, c, d, e. Each time the values may be assigned to different keys keys. Size of the dictionary may change as well.
I am interested in two values. Let's call them b and d.
Is there any algorithm that determine situations when b appears earlier than d (i.e. b's key is smaller than d's) and when d appears earlier than b (i.e. d's key is is smaller than b's)? | Determine position of values in dictionary, Python | 0 | 0 | 0 | 5,837 |
4,428,613 | 2010-12-13T12:04:00.000 | 1 | 0 | 0 | 0 | python,mysql | 4,428,933 | 5 | false | 0 | 0 | I agree with Mchi, there is no problem storing "pickled" data if you don't need to search or do relational type operations.
Denormalisation is also an important tool that can scale up database performance when applied correctly.
It's probably a better idea to use JSON instead of pickles. It only uses a little more space, and makes it possible to use the database from languages other than Python | 4 | 2 | 0 | Many times while creating database structure, I get stuck at the question, what would be more effective, storing data in pickled format in a column in the same table or create additional table and then use JOIN.
Which path should be followed, any advice ?
For example:
There is a table of Customers, containing fields like Name, Address
Now for managing Orders (each customer can have many), you can either create an Order table or store the orders in a serialized format in a separate column in the Customers table only. | Is it a good practice to use pickled data instead of additional tables? | 0.039979 | 1 | 0 | 159 |
4,428,613 | 2010-12-13T12:04:00.000 | 2 | 0 | 0 | 0 | python,mysql | 4,429,509 | 5 | true | 0 | 0 | Mixing SQL databases and pickling seems to ask for trouble. I'd go with either sticking all data in the SQL databases or using only pickling, in the form of the ZODB, which is a Python only OO database that is pretty damn awesome.
Mixing makes case sometimes, but is usually just more trouble than it's worth. | 4 | 2 | 0 | Many times while creating database structure, I get stuck at the question, what would be more effective, storing data in pickled format in a column in the same table or create additional table and then use JOIN.
Which path should be followed, any advice ?
For example:
There is a table of Customers, containing fields like Name, Address
Now for managing Orders (each customer can have many), you can either create an Order table or store the orders in a serialized format in a separate column in the Customers table only. | Is it a good practice to use pickled data instead of additional tables? | 1.2 | 1 | 0 | 159 |
4,428,613 | 2010-12-13T12:04:00.000 | 0 | 0 | 0 | 0 | python,mysql | 4,432,349 | 5 | false | 0 | 0 | I agree with @Lennart Regebro. You should probably see whether you need a Relational DB or an OODB. If RDBMS is your choice, I would suggest you stick with more tables. IMHO, pickling may have issues with scalability. If thats what you want, you should look at ZODB. It is pretty good and supports caching etc for better performance | 4 | 2 | 0 | Many times while creating database structure, I get stuck at the question, what would be more effective, storing data in pickled format in a column in the same table or create additional table and then use JOIN.
Which path should be followed, any advice ?
For example:
There is a table of Customers, containing fields like Name, Address
Now for managing Orders (each customer can have many), you can either create an Order table or store the orders in a serialized format in a separate column in the Customers table only. | Is it a good practice to use pickled data instead of additional tables? | 0 | 1 | 0 | 159 |
4,428,613 | 2010-12-13T12:04:00.000 | 3 | 0 | 0 | 0 | python,mysql | 4,428,635 | 5 | false | 0 | 0 | Usually it's best to keep your data normalized (i.e. create more tables). Storing data 'pickled' as you say, is acceptable, when you don't need to perform relational operations on them. | 4 | 2 | 0 | Many times while creating database structure, I get stuck at the question, what would be more effective, storing data in pickled format in a column in the same table or create additional table and then use JOIN.
Which path should be followed, any advice ?
For example:
There is a table of Customers, containing fields like Name, Address
Now for managing Orders (each customer can have many), you can either create an Order table or store the orders in a serialized format in a separate column in the Customers table only. | Is it a good practice to use pickled data instead of additional tables? | 0.119427 | 1 | 0 | 159 |
4,429,462 | 2010-12-13T13:51:00.000 | 1 | 0 | 1 | 0 | python | 4,429,666 | 9 | false | 0 | 0 | Think about what it will do, at present, if you give it, say a=32 and b=2. b*b will give you 4, 16, 256...
So, you have to keep track of the original b as you're calling your function recursively. You could have a third variable with a default value (original_b), but there's a way to do it without replacing b at all. | 2 | 1 | 0 | I am doing exercise on Singpath and I am stuck at this question. This question is under recursion exercises but I have no idea what the question means.
A number, a, is a power of b if it is
divisible by b and a/b is a power of
b.
Write a function called is_power
that takes parameters a and b and
returns True if a is a power of b.
Update:
Just thought of the answer and I've posted it below. | Python Recursion Exercise | 0.022219 | 0 | 0 | 4,300 |
4,429,462 | 2010-12-13T13:51:00.000 | 0 | 0 | 1 | 0 | python | 4,429,802 | 9 | false | 0 | 0 | You should start with the trivial cases, there are two in fact: is_power(x,x) and is_power(1,x).
Once you have the edge case you just need to write down the definition correctly. It mentions a/b and b, but you wrote return is_power(a,b*b). Maybe you think that is the same, just scaled both arguments with b, but it is not. Think about the values of b in is_power(27,3). | 2 | 1 | 0 | I am doing exercise on Singpath and I am stuck at this question. This question is under recursion exercises but I have no idea what the question means.
A number, a, is a power of b if it is
divisible by b and a/b is a power of
b.
Write a function called is_power
that takes parameters a and b and
returns True if a is a power of b.
Update:
Just thought of the answer and I've posted it below. | Python Recursion Exercise | 0 | 0 | 0 | 4,300 |
4,430,227 | 2010-12-13T15:10:00.000 | 0 | 1 | 0 | 1 | python,winapi,api,performancecounter | 4,430,461 | 2 | false | 0 | 0 | You could just call the C# StopWatch class directly from Python couldn't you? Maybe a small wrapper is needed (don't know Python/C# interop details - sorry) - if you are already using C# for data acquisition, doing the same for timings via Stopwatch should be simpler than anything else you can do. | 1 | 4 | 0 | I have a python script that calls a USB-based data-acquisition C# dotnet executable. The main python script does many other things, e.g. it controls a stepper motor. We would like to check the relative timing of various operations, for that purpose the dotnet exe generates a log with timestamps from C# Stopwatch.GetTimestamp(), which as far as I know yields the same number as calls to win32 API QueryPerformanceCounter().
Now I would like to get similar numbers from the python script. time.clock() returns such values, unfortunately it subtracts the value obtained at the time of 1st call to time.clock(). How can I get around this? Is it easy to call QueryPerformanceCounter() from some existing python module or do I have to write my own python extension in C?
I forgot to mention, the python WMI module by Tim Golden does this:
wmi.WMI().Win32_PerfRawData_PerfOS_System()[0].Timestamp_PerfTime
, but it is too slow, some 48ms overhead. I need something with <=1ms overhead. time.clock() seems to be fast enough, as is c# Stopwatch.GetTimestamp().
TIA,
Radim | python on win32: how to get absolute timing / CPU cycle-count | 0 | 0 | 0 | 1,794 |
4,430,408 | 2010-12-13T15:26:00.000 | 1 | 1 | 0 | 1 | python,linux,ubuntu,ssh | 4,430,456 | 2 | false | 0 | 0 | A very quick alternative is to pipe the output of your python program to a file, and then simply using tail with the second user to see the output as it's being written to the file. However, with a program like you have there, the file will very quickly become massive. | 1 | 2 | 0 | I have a script, called test.py, that does the following:
while (1):
....print "hello world"
(this script simply prints 'hello world' continuously).
Now, I am using two machines (machine A and machine B). Same user is used for both machines. I would like to do the following:
(1) [working with machine A] run test.py programatically on machine A { meaning, a local python script will be running test.py using say os.system(....) }
( at this point, the script test.py is printing "hello world" to the screen of machine A )
(2) [working with machine B] I now want to log in into machine A using ssh and 'view' the output of the script that we ran in (1)
How do I achieve this? I know how to write the script that will be running and starting test.py on machine A. I also know how to ssh from machine B to machine A.
What I don't know is:
(*) What command should I use in (1) in order to run the python script so that its output can be easily viewed while logging from a different machine (machine B) to machine A?
(*) Following the ssh from machine B to machine A, how do I 'navigate' to the screen that shows the output of test.py? | View Script Output Over SSH? | 0.099668 | 0 | 0 | 1,034 |
4,432,208 | 2010-12-13T18:31:00.000 | -1 | 0 | 1 | 0 | python,python-2.7,syntax,operators,modulo | 68,943,352 | 20 | false | 0 | 0 | def absolute(c):
if c>=0:
return c
else:
return c*-1
x=int(input("Enter the value:"))
a=absolute(x)
print(a) | 3 | 262 | 0 | What does the % in a calculation? I can't seem to work out what it does.
Does it work out a percent of the calculation for example: 4 % 2 is apparently equal to 0. How? | What is the result of % in Python? | -0.01 | 0 | 0 | 1,214,655 |
4,432,208 | 2010-12-13T18:31:00.000 | 1 | 0 | 1 | 0 | python,python-2.7,syntax,operators,modulo | 4,432,250 | 20 | false | 0 | 0 | The % (modulo) operator yields the remainder from the division of the first argument by the second. The numeric arguments are first converted to a common type.
3 + 2 + 1 - 5 + 4 % 2 - 1 / 4 + 6 = 7
This is based on operator precedence. | 3 | 262 | 0 | What does the % in a calculation? I can't seem to work out what it does.
Does it work out a percent of the calculation for example: 4 % 2 is apparently equal to 0. How? | What is the result of % in Python? | 0.01 | 0 | 0 | 1,214,655 |
4,432,208 | 2010-12-13T18:31:00.000 | 49 | 0 | 1 | 0 | python,python-2.7,syntax,operators,modulo | 19,524,230 | 20 | false | 0 | 0 | The modulus is a mathematical operation, sometimes described as "clock arithmetic." I find that describing it as simply a remainder is misleading and confusing because it masks the real reason it is used so much in computer science. It really is used to wrap around cycles.
Think of a clock: Suppose you look at a clock in "military" time, where the range of times goes from 0:00 - 23.59. Now if you wanted something to happen every day at midnight, you would want the current time mod 24 to be zero:
if (hour % 24 == 0):
You can think of all hours in history wrapping around a circle of 24 hours over and over and the current hour of the day is that infinitely long number mod 24. It is a much more profound concept than just a remainder, it is a mathematical way to deal with cycles and it is very important in computer science. It is also used to wrap around arrays, allowing you to increase the index and use the modulus to wrap back to the beginning after you reach the end of the array. | 3 | 262 | 0 | What does the % in a calculation? I can't seem to work out what it does.
Does it work out a percent of the calculation for example: 4 % 2 is apparently equal to 0. How? | What is the result of % in Python? | 1 | 0 | 0 | 1,214,655 |
4,432,606 | 2010-12-13T19:19:00.000 | 2 | 0 | 1 | 0 | visual-studio-2010,ironpython,ironpython-studio | 7,561,040 | 2 | false | 1 | 0 | I had a similar issue with IronPython 2.7 RTM on VS 2010 SP1. I had the python tools for VS 1.0 installed before I installed IronPython. I did the following to resolve the issue
Uninstalled IronPython
Uninstalled Python tools for VS
Installed IronPython 2.7 RTM without the "Tools for VS" feature, this is provided by the python for VS installer
Installed Python Tools for VS | 1 | 1 | 0 | I installed IronPython yesterday. After running Visual Studio the IronPython project template showed up but later it was gone. I've tried repairing, uninstalling, and reinstalling without fixing the issue. How can I make the templates show up? | How can I fix missing IronPython project templates in Visual Studio 2010? | 0.197375 | 0 | 0 | 1,945 |
4,434,959 | 2010-12-14T00:55:00.000 | 3 | 1 | 1 | 0 | python,barcode,barcode-scanner | 4,435,008 | 2 | false | 0 | 0 | Are you making a python web-app or a client application? Unless you're looking for specialized bar code scanning functionality it doesn't really matter since the input from the scanner appears like keyboard entry (sometimes prefixed with a special input character), so you just have to have a way of listening to the keyboard input and catching that special character. | 1 | 11 | 0 | I'm doing some feasibility research with regards to a (large) book cataloging project. Any help would w/r/t good sources of information would be appreciated but the things I would specifically like to know are:
1.)does python have any modules for use with barcode readers (preferably USB)? What other programs are available for reading barcode information?
2.)This may be better answered with a few sources of information, but what kinds of things should I look for in a barcode scanner, especially if I'm looking to scan, specifically, a lot of barcodes on books.
3.)This may also be better answered with a few sources of information, what kind of information is stored standard in a book's barcode.
I know this is relatively off-topic, but any help would be greatly appreciated. | USB Barcode scanner research | 0.291313 | 0 | 0 | 4,396 |
4,435,882 | 2010-12-14T04:31:00.000 | 0 | 0 | 0 | 0 | python,html,url,printing | 4,435,929 | 2 | false | 1 | 0 | Fetch it (using mechanize, urllib or whatever else you want), parse what you get (using elementtree, BeautifulSoup, lxml or whatever else you want) and you have what you want. | 1 | 1 | 0 | How would you get all the HTML tags from a URL and print them? | How to get html tags from url? | 0 | 0 | 1 | 646 |
4,437,307 | 2010-12-14T08:42:00.000 | 8 | 0 | 0 | 1 | python,google-app-engine,forms,submit,datastore | 4,437,354 | 3 | false | 1 | 0 | Sounds like you want to look into AJAX. The simplest way to do this is probably to use the ajax functions in one of the popular Javascript libraries, like jQuery. | 2 | 0 | 0 | As a newbie to app engine and python I can follow the examples given by Google and have created a python application with a template HTML page where I can enter data, submit it to the datastore and by reading back the data, just sent, recreate the sending page so I can continue adding data and store again. However what I would like to do is submit the data, have it stored in the datastore without the sending page being refreshed. It seems like a waste of traffic to have all the data sent back again. | How do you submit a form to an app engine python application without refreshing the sending page? | 1 | 0 | 0 | 514 |
4,437,307 | 2010-12-14T08:42:00.000 | -1 | 0 | 0 | 1 | python,google-app-engine,forms,submit,datastore | 4,439,461 | 3 | false | 1 | 0 | Have a look at Pyjamas pyjs.org
It's a Python Compiler for web browsers. Write your client side in Python and Pyjamas will compile it into JavaScript. | 2 | 0 | 0 | As a newbie to app engine and python I can follow the examples given by Google and have created a python application with a template HTML page where I can enter data, submit it to the datastore and by reading back the data, just sent, recreate the sending page so I can continue adding data and store again. However what I would like to do is submit the data, have it stored in the datastore without the sending page being refreshed. It seems like a waste of traffic to have all the data sent back again. | How do you submit a form to an app engine python application without refreshing the sending page? | -0.066568 | 0 | 0 | 514 |
4,437,331 | 2010-12-14T08:47:00.000 | 18 | 1 | 0 | 1 | python,ssh | 4,441,673 | 2 | true | 0 | 0 | Try pssh -O StrictHostKeyChecking=no. This works for me.
By default ssh uses the value of "ask", which causes it to ask the user whether to continue connecting to unknown host. By setting the value to "no", you avoid the question, but are no longer protected against certain attacks. E.g. if you are connecting to hostA, and someone puts hostB there with the same IP address, then by default ssh will notice that hostB has changed, and will prompt you about it. With StrictHostKeyChecking=no, it will silently assume everything is OK. | 1 | 5 | 0 | when I use pssh, trying to access a remote machine which is not inside the UNIX
known hosts file, pssh freeze after giving the password.
After having added the host using a direct ssh command, pssh works.
So is there an option to give to the pssh command in order to avoid this problem ?
Thanks for your help,
Regards | pssh and known_hosts file | 1.2 | 0 | 0 | 12,459 |
4,438,020 | 2010-12-14T10:12:00.000 | 0 | 0 | 1 | 1 | python,windows | 61,368,121 | 11 | false | 0 | 0 | Above mentioned all the methods did not worked I tried them all , I will tell you more simpler solution and alternative of windows task scheduler
Create a .bat file with content
"ADDRESS OF YOUR PROJECT INTERPRETER" "ADDRESS OF YOUR PYTHON SCRIPT WITH SCRIPT NAME"
Store this bat file into the window startup folder(by default hidden)
FYI: to find window startup folder
press windos+r then
type shell:startup -- it will directly take you to the startup folder
copy the bat file there with following 2 address in the same format ,
then simply restart the system or shut down and boot up.
The code will automatically run within 20 seconds of opening.
Thank me later | 4 | 80 | 0 | I have a python file and I am running the file.
If Windows is shutdown and booted up again, how I can run that file every time Windows starts? | How to start a python file while Windows starts? | 0 | 0 | 0 | 132,882 |
4,438,020 | 2010-12-14T10:12:00.000 | 1 | 0 | 1 | 1 | python,windows | 22,035,422 | 11 | false | 0 | 0 | try adding an entry to "HKLM/SOFTWARE\Microsoft\Windows\CurrentVersion\RunOnce" .
Right click ->new -> string value -> add file path | 4 | 80 | 0 | I have a python file and I am running the file.
If Windows is shutdown and booted up again, how I can run that file every time Windows starts? | How to start a python file while Windows starts? | 0.01818 | 0 | 0 | 132,882 |
4,438,020 | 2010-12-14T10:12:00.000 | 9 | 0 | 1 | 1 | python,windows | 66,016,922 | 11 | false | 0 | 0 | click Win+R
type shell:startup
drag and drop your python file my_script.py
if you don't need the console:
change extension from my_script.py to my_script.pyw
else:
create run_my_script.cmd with content: python path\to\your\my_script.py | 4 | 80 | 0 | I have a python file and I am running the file.
If Windows is shutdown and booted up again, how I can run that file every time Windows starts? | How to start a python file while Windows starts? | 1 | 0 | 0 | 132,882 |
4,438,020 | 2010-12-14T10:12:00.000 | 70 | 0 | 1 | 1 | python,windows | 4,439,204 | 11 | false | 0 | 0 | Depending on what the script is doing, you may:
package it into a service, that should then be installed
add it to the windows registry (HKCU\Software\Microsoft\Windows\CurrentVersion\Run)
add a shortcut to it to the startup folder of start menu - its location may change with OS version, but installers always have some instruction to put a shortcut into that folder
use windows' task scheduler, and then you can set the task on several kind of events, including logon and on startup.
The actual solution depends on your needs, and what the script is actually doing.
Some notes on the differences:
Solution #1 starts the script with the computer, while solution #2 and #3 start it when the user who installed it logs in.
It is also worth to note that #1 always start the script, while #2 and #3 will start the script only on a specific user (I think that if you use the default user then it will start on everyone, but I am not sure of the details).
Solution #2 is a bit more "hidden" to the user, while solution #3 leaves much more control to the user in terms of disabling the automatic start.
Finally, solution #1 requires administrative rights, while the other two may be done by any user.
Solution #4 is something I discovered lately, and is very straightforward. The only problem I have noticed is that the python script will cause a small command window to appear.
As you can see, it all boils down to what you want to do; for instance, if it is something for your purposes only, I would simply drag it into startup folder.
In any case, lately I am leaning on solution #4, as the quickest and most straightforward approach. | 4 | 80 | 0 | I have a python file and I am running the file.
If Windows is shutdown and booted up again, how I can run that file every time Windows starts? | How to start a python file while Windows starts? | 1 | 0 | 0 | 132,882 |
4,438,516 | 2010-12-14T11:11:00.000 | 2 | 0 | 1 | 0 | python,conditional-statements,goto | 4,438,582 | 5 | false | 0 | 0 | Python is designed to support good coding practices and GOTO is not one of them. It may lead to unreadable program logic, if not used properly.
I suggest to learn code your program in a Python way, do not stick with (sometimes bad) habits from other programming languages. See Python documentation, real mature Python programs and learn. | 1 | 5 | 0 | Since there is no goto operator in Python, what technique can be used instead?
Condition
If it is true, go to thread 1, if is false, go to thread 2
In thread we do something small and after that we go to thread 2 where all other actions take place. | Equivalent to GOTO in conditions, Python | 0.07983 | 0 | 0 | 38,829 |
4,438,644 | 2010-12-14T11:29:00.000 | 1 | 0 | 1 | 1 | windows-7,curl,python-3.x | 4,439,344 | 1 | false | 0 | 0 | There is no module called "curl", so it's unclear what you mean?
PycURL?
friendly_curl?
pylibcurl?
curlwrapper?
pyparallelcurl?
In any case, as far as I can gather, none of them are ported to Python 3, so the answer on how to install them on Python 3 is: Talk to the authors and help port them! It's fun! | 1 | 0 | 0 | Can you please tell how to install curl for python 3.x to Windows 7. Ease_install only for the 2 version of the sort. | How to install curl on python 3.x in Windows 7? | 0.197375 | 0 | 0 | 907 |
4,440,341 | 2010-12-14T14:44:00.000 | 0 | 0 | 1 | 0 | python,computer-science,computer-science-theory | 5,954,608 | 5 | true | 0 | 0 | I finally decided to use a mixture of online resources. I am teaching him basics of CS and basic Python myself. Then I will cherry pick topics for him from various free python books and official documentations.
Let's see how this experiment goes. | 1 | 2 | 0 | In our office, we have an office boy(completed high school(10+2 years)) with average academic record so far). He wants to learn programming. I have started coaching him in Computer Science basics (history of computer science, number systems, etc.), but I am not able to put in enough time with him(because I have very limited free time and more importantly I do not want to spoon feed him). Now I am not sure how to fill in the gap of theoretical reading.
Now my question is, could anyone point me to some online resources(preferably in simple English) for Introduction to Computer Sciences.
Moreover, I am planning to start him with on programming with book Think Like A Computer Scientist - Python version. If any body knows a better book or an online resource - preferably in Python, please point out.
Thanks | Online resources for Introduction to computer and computer sciences for absolute beginner | 1.2 | 0 | 0 | 321 |
4,441,209 | 2010-12-14T16:05:00.000 | 1 | 0 | 0 | 0 | python,django,nosql,scaling,partitioning | 4,441,374 | 1 | false | 1 | 0 | Problem A: how to keep the query for items added by people you are following working well with growing datasets?
starting with a dataset of (who are my followers / who am i following); one could save these values as tuples and segmentate them across several SQL databases (though I doubt real segmentation is really needed even for twitter size databases). This would give the list of people who are followed. Secondly, a table for follower->items, sorted by follower could be easily queried; and also segmentated if needed given humongous datasets.
Problem B: we are seeing geographically disperse traffic. large userbase in the netherlands and brazil. any solution would probably need to allow for databases across multiple data centers.
one could designate a master database (cluster) and a slave databse (cluster), and replicate data from the master to the slave. However, this does imply the data is always saved to the master database. data queries can be done locally.
Another option is to run the database (clusters) in a master-master setup; but this is generally more trouble then it is worth. | 1 | 1 | 0 | The problem is somewhat similar to twitter/facebook's:
followers and following
users add items
Subsequently you see the items added by all the people you are following.
Problem A: how to keep the query for items added by people you are following working well with growing datasets?
Problem B: we are seeing geographically disperse traffic. large userbase in the netherlands and brazil. any solution would probably need to allow for databases across multiple data centers.
We are running on a django/python stack. Already running edge server caching. (Anonymous users get the cached version, logged in user's version is run through a second level template parsing service first) | Scaling a follower model | 0.197375 | 0 | 0 | 185 |
4,441,933 | 2010-12-14T17:06:00.000 | 0 | 1 | 0 | 0 | php,python,design-patterns,cron,screen-scraping | 4,441,983 | 3 | false | 1 | 0 | Do you need to run the script 50 times per user, or only when the user has logged into your service to check on things? | 2 | 0 | 0 | On the front-end, I have a PHP webapp that allows users to create a list of their websites (5 max).
On the back-end, a Python script runs daily (and has ~10 iterations) for each website that the user registers. Each script per website takes about 10 seconds to run through all iterations and finish its scraping. It then makes a CSV file with its findings.
So, in total, that's up to (5 websites * 10 iterations =) 50 iterations at 8.3 total minutes per user.
Right now, the script works when I manually feed it a URL, so I'm wondering how to make it dynamically part of the webapp.
How do I programmatically add and remove scripts that run daily depending on the number of users and the websites each user has each day?
How would I schedule this script to run for each website of each user, passing in the appropriate parameters?
I'm somewhat acquainted with cronjobs, as it's the only thing I know of that is made for routine processes. | Best practice for running a daily Python screen-scraping script 50 times (8.3 minutes total) per user? | 0 | 0 | 0 | 772 |
4,441,933 | 2010-12-14T17:06:00.000 | 0 | 1 | 0 | 0 | php,python,design-patterns,cron,screen-scraping | 4,441,994 | 3 | false | 1 | 0 | Assuming you're using a database to store the users' web sites, you can have just 1 script that runs as a daily cron job and queries the database for the list of sites to process. | 2 | 0 | 0 | On the front-end, I have a PHP webapp that allows users to create a list of their websites (5 max).
On the back-end, a Python script runs daily (and has ~10 iterations) for each website that the user registers. Each script per website takes about 10 seconds to run through all iterations and finish its scraping. It then makes a CSV file with its findings.
So, in total, that's up to (5 websites * 10 iterations =) 50 iterations at 8.3 total minutes per user.
Right now, the script works when I manually feed it a URL, so I'm wondering how to make it dynamically part of the webapp.
How do I programmatically add and remove scripts that run daily depending on the number of users and the websites each user has each day?
How would I schedule this script to run for each website of each user, passing in the appropriate parameters?
I'm somewhat acquainted with cronjobs, as it's the only thing I know of that is made for routine processes. | Best practice for running a daily Python screen-scraping script 50 times (8.3 minutes total) per user? | 0 | 0 | 0 | 772 |
4,441,947 | 2010-12-14T17:07:00.000 | 4 | 0 | 1 | 0 | python,list,memory | 6,846,141 | 5 | false | 0 | 0 | I had a similar problem using a 32-bit version of python in a 64-bit windows environment. I tried the 64-bit windows version of python and very quickly ran into troubles with the Scipy libraries compiled for 64-bit windows.
The totally free solution that I implemented was
1) Install VirtualBox
2) Install CentOS 5.6 on the VM
3) Get the Enthought Python Distribution (Free 64 bit Linux Version).
Now all of my Numpy, Scipy, and Matplotlib dependant python code can use as much memory as I have Ram and available Linux swap. | 2 | 23 | 0 | I am building a large data dictionary from a set of text files. As I read in the lines and process them, I append(dataline) to a list.
At some point the append() generates a Memory Error exception. However, watching the program run in the Windows Task Manager, at the point of the crash I see 4.3 GB available and 1.1 GB free.
Thus, I do not understand the reason for the exception.
Python version is 2.6.6. I guess, the only reason is that it is not able to use more of the available RAM. If this is so, is it possible to increase the allocation? | Why Python `Memory Error` with list `append()` lots of RAM left | 0.158649 | 0 | 0 | 51,737 |
4,441,947 | 2010-12-14T17:07:00.000 | 3 | 0 | 1 | 0 | python,list,memory | 26,113,468 | 5 | false | 0 | 0 | I had a similar problem happening when evaluating an expression containing large numpy arrays (actually, one was sparse). I was doing this on a machine with 64GB of memory, of which only about 8GB was in use, so was surprised to get the MemoryError.
It turned out that my problem was array shape broadcasting: I had inadvertently duplicated a large dimension.
It went something like this:
I had passed an array with shape (286577, 1) where I was expecting (286577).
This was subracted from an array with shape (286577, 130).
Because I was expecting (286577), I applied [:,newaxis] in the expression to bring it to (286577,1) so it would be broadcast to (286577,130).
When I passed shape (286577,1) however, [:,newaxis] produced shape (286577,1,1) and the two arrays were both broadcast to shape (286577,286577,130) ... of doubles. With two such arrays, that comes to about 80GB! | 2 | 23 | 0 | I am building a large data dictionary from a set of text files. As I read in the lines and process them, I append(dataline) to a list.
At some point the append() generates a Memory Error exception. However, watching the program run in the Windows Task Manager, at the point of the crash I see 4.3 GB available and 1.1 GB free.
Thus, I do not understand the reason for the exception.
Python version is 2.6.6. I guess, the only reason is that it is not able to use more of the available RAM. If this is so, is it possible to increase the allocation? | Why Python `Memory Error` with list `append()` lots of RAM left | 0.119427 | 0 | 0 | 51,737 |
4,443,509 | 2010-12-14T19:50:00.000 | 0 | 1 | 1 | 0 | python | 4,443,870 | 5 | false | 0 | 0 | If the two modules are unrelated except for that common function, you may wish to consider extracting that function (and maybe other things that are related to that function) into a third module. | 3 | 0 | 0 | I have around 80 lines of a function in a file. I need the same functionality in another file so I am currently importing the other file for the function.
My question is that in terms of running time on a machine which technique would be better :- importing the complete file and running the function or copying the function as it is and run it from same package.
I know it won't matter in a large sense but I want to learn it in the sense that if we are making a large project is it better to import a complete file in Python or just add the function in the current namespace..... | Is importing a file good in Python | 0 | 0 | 0 | 143 |
4,443,509 | 2010-12-14T19:50:00.000 | 1 | 1 | 1 | 0 | python | 4,443,553 | 5 | false | 0 | 0 | Importing is good cause it helps you manage stuff easily. What if you needed the same function again? Instead of making changes at multiple places, there is just one centralized location - your module.
In case the function is small and you won't need it anywhere else, put it in the file itself.
If it is complex and would require to be used again, separate it and put it inside a module.
Performance should not be your concern here. It should hardly matter. And even if it does, ask yourself - does it matter to you? | 3 | 0 | 0 | I have around 80 lines of a function in a file. I need the same functionality in another file so I am currently importing the other file for the function.
My question is that in terms of running time on a machine which technique would be better :- importing the complete file and running the function or copying the function as it is and run it from same package.
I know it won't matter in a large sense but I want to learn it in the sense that if we are making a large project is it better to import a complete file in Python or just add the function in the current namespace..... | Is importing a file good in Python | 0.039979 | 0 | 0 | 143 |
4,443,509 | 2010-12-14T19:50:00.000 | 4 | 1 | 1 | 0 | python | 4,443,551 | 5 | true | 0 | 0 | Importing is how you're supposed to do it. That's why it's possible. Performance is a complicated question, but in general it really doesn't matter. People who really, really need performance, and can't be satisfied by just fixing the basic algorithm, are not using Python in the first place. :) (At least not for the tiny part of the project where the performance really matters. ;) ) | 3 | 0 | 0 | I have around 80 lines of a function in a file. I need the same functionality in another file so I am currently importing the other file for the function.
My question is that in terms of running time on a machine which technique would be better :- importing the complete file and running the function or copying the function as it is and run it from same package.
I know it won't matter in a large sense but I want to learn it in the sense that if we are making a large project is it better to import a complete file in Python or just add the function in the current namespace..... | Is importing a file good in Python | 1.2 | 0 | 0 | 143 |
4,445,117 | 2010-12-14T22:54:00.000 | 0 | 0 | 0 | 0 | sql-server-2008,stored-procedures,python-2.6,call-graph | 18,523,367 | 3 | false | 0 | 0 | SQL Negotiator Pro has a free lite version at www.aphilen.com
The full version is the only product out there that will find all dependencies and not stop after finding the first 10 child dependencies. Other products fail when there is a circular reference and just hang, these guys have covered this off. Also a neat feature is the ability to add notes to the diagram so that it can be easily distributed.
Full version is not cheap but has saved us plenty of hours usually required figuring out complex database procedures. apex also provide a neat tool | 1 | 8 | 0 | I would like to be able to plot a call graph of a stored procedure. I am not interested in every detail, and I am not concerned with dynamic SQL (although it would be cool to detect it and skip it maybe or mark it as such.)
I would like the tool to generate a tree for me, given the server name, db name, stored proc name, a "call tree", which includes:
Parent stored procedure.
Every other stored procedure that is being called as a child of the caller.
Every table that is being modified (updated or deleted from) as a child of the stored proc which does it.
Hopefully it is clear what I am after; if not - please do ask. If there is not a tool that can do this, then I would like to try to write one myself. Python 2.6 is my language of choice, and I would like to use standard libraries as much as possible. Any suggestions?
EDIT: For the purposes of bounty Warning: SQL syntax is COMPLEX. I need something that can parse all kinds of SQL 2008, even if it looks stupid. No corner cases barred :)
EDIT2: I would be OK if all I am missing is graphics. | Is there a free tool which can help visualize the logic of a stored procedure in SQL Server 2008 R2? | 0 | 1 | 0 | 6,375 |
4,447,658 | 2010-12-15T07:29:00.000 | 1 | 0 | 0 | 0 | networking,graph,wxpython,pygraphviz | 4,493,216 | 1 | false | 0 | 0 | Take a look at the wx.lib.ogl package. It has the basics of what you would need to build diagrams of shapes, labels, lines, arrows, etc. and you can allow the user to interact with them to move them around the window, etc. It is not perfect, but people are using it for this type of thing quite a bit.
Another possibility for you might be wx.lib.floatcanvas. They both have their strengths and weaknesses, so it really depends on which is the best fit for your needs. | 1 | 1 | 0 | Hi
I would like to create a wxpython application with a window where I can create a network graph. I have heard (never used) of graphviz and NetworkX, but it seems to me that they only creates graph given some input data. I would like to do the opposite - i.e., create drag and drop nodes and links from a pallete menu. The nodes and links should be right-clickable with context menu popups. Eg., I should be able to right click a node and click "properties" in context menu - where I can fill in ip address, number of ports, their mac addresses etc.
I believe graphviz will not allow me to do that. Is there any good package to do this ? Must be free / open-source. | wxPython: Network Graph - clickable with context menu - Any pkgs? | 0.197375 | 0 | 1 | 943 |
4,449,473 | 2010-12-15T11:39:00.000 | 4 | 0 | 1 | 0 | python,linux,file | 4,449,505 | 2 | false | 0 | 0 | Your operating system is caching the file.
What? This means, the first time you read the file, your program had to go look for the information in the hard drive, and hard drives are slooooow.
Now, after having read the whole file for the first time, Linux kept it around in memory just in case, and probably because there was nothing important to have instead at the time. So, the second time you read it, you were accessing the copy in memory, without reaching for the hard drive, which is orders of magnitude faster.
Cheers! | 1 | 2 | 0 | SIZE = 1<<16
def justread(file):
with open(file, 'rb') as f:
while f.read(SIZE):
pass
The first time I run this function on a 700MB file it took 19 secs.
When I repeated
reading the same file again the time it took dropped to 0.5secs.
I repeated this with many files and the results were similar.
What is going on here? | Why file read is faster on reading again? | 0.379949 | 0 | 0 | 476 |
4,450,144 | 2010-12-15T13:02:00.000 | 8 | 0 | 1 | 0 | python,io | 4,450,277 | 7 | false | 0 | 0 | If it should be human-readable, I'd
also go with JSON. Unless you need to
exchange it with enterprise-type
people, they like XML better. :-)
If it should be human editable and
isn't too complex, I'd probably go
with some sort of INI-like format,
like for example configparser.
If it is complex, and doesn't need to
be exchanged, I'd go with just
pickling the data, unless it's very
complex, in which case I'd use ZODB.
If it's a LOT of data, and needs to
be exchanged, I'd use SQL.
That pretty much covers it, I think. | 1 | 14 | 1 | What is the easiest way to save and load data in python, preferably in a human-readable output format?
The data I am saving/loading consists of two vectors of floats. Ideally, these vectors would be named in the file (e.g. X and Y).
My current save() and load() functions use file.readline(), file.write() and string-to-float conversion. There must be something better. | easy save/load of data in python | 1 | 0 | 0 | 62,035 |
4,450,752 | 2010-12-15T14:07:00.000 | 3 | 0 | 1 | 0 | python,if-statement | 4,450,795 | 4 | false | 0 | 0 | Note: If you can put the elements as keys of a dict then testing for membership is much quicker thanks to the hashing algorithm. Will only be an issue if your list is very long or your app does a lot of this kind of thing. Otherwise, "X not in Y" as Sven says. | 1 | 11 | 0 | Let's say there is a list a that contains both numbers and letters. Is there quick way to find out that the list doesn't contain some specific element. I plan to use it in conditions. | Python, find out that a list does not have specific item | 0.148885 | 0 | 0 | 32,752 |
4,451,166 | 2010-12-15T14:50:00.000 | 1 | 0 | 0 | 0 | python,windows,wxpython | 4,465,221 | 3 | false | 0 | 1 | The simple answer is that the wx.ListBox doesn't support that. Try using a one column wx.ListCtrl (in Report mode) instead. | 2 | 2 | 0 | I'm using a wxPython listbox on Windows to get a choice from the user, and I would like them to be able to select an item using the ENTER key, as if they had double-clicked. I know how to do this in C or C++ using the Windows API directly, but can't seem to find how to do it using wxPython. Anyone know how? It seems like an obvious thing to want to do. | Keyboard interface to wxPython listbox | 0.066568 | 0 | 0 | 721 |
4,451,166 | 2010-12-15T14:50:00.000 | 1 | 0 | 0 | 0 | python,windows,wxpython | 4,451,586 | 3 | false | 0 | 1 | Maybe I'm missing some nuance, there wasn't much info to go on, but it sounds like you could accomplish this by catching the keydown event, matching for enter and then calling your on_doubleclick function. Unless there's an implicit double-click handling you should be good to go. | 2 | 2 | 0 | I'm using a wxPython listbox on Windows to get a choice from the user, and I would like them to be able to select an item using the ENTER key, as if they had double-clicked. I know how to do this in C or C++ using the Windows API directly, but can't seem to find how to do it using wxPython. Anyone know how? It seems like an obvious thing to want to do. | Keyboard interface to wxPython listbox | 0.066568 | 0 | 0 | 721 |
4,451,464 | 2010-12-15T15:12:00.000 | 0 | 0 | 0 | 0 | python,pygame | 4,474,154 | 4 | false | 0 | 1 | Depends on the size of the map you want to make, however, with the actual technologies it's very hard to see a tile-map "rendered" to take longer than expected, tiled based games are almost extinguished, however is always a good practice and a starting point to the world of game programming | 3 | 5 | 0 | I am trying to decide if it is better to use a pre-rendered large image for a scrolling map game or to render the tiles individual on screen each frame. I have tried to program the game both ways and don't see any obvious difference in speed, but that might be due to my lack of experiences.
Besides for memory, is there a speed reasons to not use a pre-rendered map? | Pygame: Tiled Map or Large Image | 0 | 0 | 0 | 2,637 |
4,451,464 | 2010-12-15T15:12:00.000 | 1 | 0 | 0 | 0 | python,pygame | 4,451,504 | 4 | false | 0 | 1 | Memory and speed are closely related. If your tile set fits in video memory, but the pre-rendered map doesn't, speed will suffer. | 3 | 5 | 0 | I am trying to decide if it is better to use a pre-rendered large image for a scrolling map game or to render the tiles individual on screen each frame. I have tried to program the game both ways and don't see any obvious difference in speed, but that might be due to my lack of experiences.
Besides for memory, is there a speed reasons to not use a pre-rendered map? | Pygame: Tiled Map or Large Image | 0.049958 | 0 | 0 | 2,637 |
4,451,464 | 2010-12-15T15:12:00.000 | 5 | 0 | 0 | 0 | python,pygame | 4,451,490 | 4 | true | 0 | 1 | The only reason I can think of for picking one over the other on modern hardware (anything as fast and with as much ram as, say, an iPhone), would be technical ones that make the game code itself easier to follow. There's not much performance wise to distinguish them.
One exception I can think of, is if you are using a truly massive background, and doing tile rendering in a GPU, tiles can be textures and you'll get a modest speed bump since you don't need to push much data between cpu and gpu per frame, and it'll use very little video ram. | 3 | 5 | 0 | I am trying to decide if it is better to use a pre-rendered large image for a scrolling map game or to render the tiles individual on screen each frame. I have tried to program the game both ways and don't see any obvious difference in speed, but that might be due to my lack of experiences.
Besides for memory, is there a speed reasons to not use a pre-rendered map? | Pygame: Tiled Map or Large Image | 1.2 | 0 | 0 | 2,637 |
4,452,208 | 2010-12-15T16:19:00.000 | 2 | 0 | 0 | 0 | python,django,packaging | 4,452,849 | 6 | true | 1 | 0 | Yes, you can package it. Django may not be the easiest to do this with, but the principles are the same for other frameworks. You need to make an installer that installs everything you need. And that installer needs to be different for different platforms. such as Windows, Ubuntu, OS X etc. That also means that the answer is significantly different for each platform, and only half of the answer is dependning on Django. :-(
This kinda sucks, but that's life, currently. There is no nice platform independent way to install software for end users. | 1 | 21 | 0 | I've made a small little "application" utilizing Django as a framework. This is an application that is not ment to be deployed to a server but run locally on a machine. Thus the runserver.py works just nice.
I, as an developer is comfortable with fireing up the terminal, running python manage.py runserver and using it.
But I have some Mac OS X and Windows friends wanting to use my application, and they dont have virtualenv, git or anything else.
Is there a way I can package this to be a standalone product? Of course it would depend on Python being installed on the system, but it is possbile to package the virtualenv — with django and everything, and just copy it to another system and make it work?
And maybe even run the runserver in some kind a deamon mode? | Package a django project and its dependencies for a standalone "product" | 1.2 | 0 | 0 | 9,313 |
4,452,735 | 2010-12-15T17:07:00.000 | 6 | 0 | 1 | 0 | c#,python | 4,452,792 | 3 | true | 0 | 0 | You can put a Main method in as many classes as you like, although only one can be an entry point for an application. (For talks, I often have a main method in every class, and use a helper library to present all of those pseudo-entry-points when I run the project.)
Likewise you can definitely add a reference to a .exe assembly and treat it like a library. For example, you could make a unit testing assembly work like a class library in most cases, but also write a main method so that you could just run it to execute the tests without a GUI or whatever. | 2 | 0 | 0 | With python, I can use if __name__ == "__main__": for using the module both as a library and a program.
Can I mimic this feature in C#?
I see a class in C# can have a 'static void Main()', but I'm not sure if every class can have a Main() without a problem.
ADDED
/m:CLASS_NAME is a way to specify the class to run the Main(). | if __name__ == "__main__": equivalent in C# | 1.2 | 0 | 0 | 901 |
4,452,735 | 2010-12-15T17:07:00.000 | 6 | 0 | 1 | 0 | c#,python | 4,452,790 | 3 | false | 0 | 0 | You can compile a C# project as a program (executable) with a Main() method, and you'd still be able to use it as a library. No special syntax required.
You could add a Main() method to every class, but I doubt it's useful.
.NET applications usually have different structures than Python ones; trying to fit the same programming model is unlikely to get you good results. | 2 | 0 | 0 | With python, I can use if __name__ == "__main__": for using the module both as a library and a program.
Can I mimic this feature in C#?
I see a class in C# can have a 'static void Main()', but I'm not sure if every class can have a Main() without a problem.
ADDED
/m:CLASS_NAME is a way to specify the class to run the Main(). | if __name__ == "__main__": equivalent in C# | 1 | 0 | 0 | 901 |
4,453,724 | 2010-12-15T18:57:00.000 | 2 | 1 | 1 | 0 | python,encryption,aes | 4,453,804 | 3 | false | 0 | 0 | Ideally, you would not be at a cipher level in order to secure your data. If nothing else, use an existing, proven secure, framework such as GPG to handle file encryption. This is driven home by your question regarding AES: you haven't even mentioned what cipher modes you were considering (CBC, XTR, CTR, CFB, EBC, etc). | 1 | 3 | 0 | I am looking to implement a simple project that backs up files and encrypts them using AES.
The normal backing up part is done thanks to how Python handles everything ... however I need to encrypt the data also.
So my questions are:
Is AES the best encryption algorithm for encrypting the files or I can do better?
What is the best Python library for encrypting stuff? I searched and came across M2Crypto and PyCrypto. Any differences/ which one should I favour?
Is this going to be secure? I mean, I will be typing the key everytime I need to encrypt / decrypt and so I will be getting the key from raw_input. Is this OK?
If you have any suggestions, feel free to let me know.
Thanks. | AES encryption of files with Python | 0.132549 | 0 | 0 | 2,086 |
4,455,197 | 2010-12-15T21:38:00.000 | 0 | 0 | 0 | 0 | python,authentication,authorization,web-frameworks | 4,638,281 | 2 | false | 1 | 0 | I have an answer, after a bit of fiddling.
The answer is that the only reason to use the authentication schema suggested in the repoze.what documentation is that if you do, you can use their predicates for free. Fortunately, writing & using your own predicates is a piece of cake. It seems to me that the only hard requirement is for a user object (although obviously you can call this whatever you want). In my app I have a bunch of custom predicates that check certain things like:
Is the user a member of this group? (group specified by a parameter)
Is the user logged in?
Does the user hold this particular site role?
I can then use these predicates wherever I want. | 1 | 0 | 0 | I'm writing a web app, and I'd like to use repoze.what & repoze.who to handle my authorisation & authentication. The problem is that repoze.what seems to be hard-coded to accept a certain permissions model, that is:
Visitors to the site are either a logged in user, or anonymous.
User accounts belong to 0 or more groups.
Groups have 0 or more permissions associated with them.
So, for example, your permissions might be 'can-post-article' and 'can-post-comment', and your groups might be 'author', 'visitor', where 'author' can both post articles & post comments, while visitors can only post comments.
That model probably works for most sites. However, my site allows teams to collaborate with each other on different levels. So the security model that I need is:
Visitors are either a logged in user, or anonymous.
Users are a member of 0 or more groups.
For each group that the user is a member of, that membership will have different permissions. For example, the user might be an 'author' or group A, but a 'commenter' on group B.
The number of groups will change over time, and the memberships of those groups will also change. I can't see any easy way to integrate this permissions model into repoze.what. Am I missing something obvious? | alternative permissions model with repoze.what | 0 | 0 | 0 | 225 |
4,455,845 | 2010-12-15T23:01:00.000 | 6 | 0 | 0 | 0 | python,django,http,ios,csrf | 4,457,172 | 2 | true | 1 | 0 | Is your goal to re-use an existing form? if so, iPhone app should GET the page with the form and then POST using the CSRF token. The whole point of CSRF tokens is that the server has to generate them.
Is your goal to authenticate the iPhone app so that other apps can't POST to your API? That is a can of worms, since any secret that you give your iPhone app can be read by anybody who has downloaded the app. | 1 | 3 | 0 | Here's the thing:
Right now, on my website template, there is {% csrf_token %} that allows my website to send a POST request of a form.
But what if my iPhone app (a client) wants to send a POST request to my web service? How do I give my iPhone app a CSRF token that it can temporarily use? | How do I generate a Django CSRF key for my iPhone and Android apps that want to send a POST request? | 1.2 | 0 | 0 | 1,747 |
4,455,973 | 2010-12-15T23:21:00.000 | 1 | 1 | 0 | 1 | python,root | 4,456,065 | 2 | false | 0 | 0 | you could copy python binary to python-suid,
chown it to user you want to run scripts as and chown u+s python-suid
then in script #!/usr/bin/python-suid | 2 | 1 | 0 | I have a python script which I would like to launch from inittab, shown below
s1:respawn:/home/a_user/app/script.py
I believe initab executes as root, so the a_user's envrinment is not available
The script needs to know "a_user" home directory for ini file settings and log file storage. I would like to avoid hard coding these paths in my script. Is it possible to execute this script as a_user and not a root? If this is possible would a_user HOME environment variable be available?
Regards | Executing a python script from inittab not as root | 0.099668 | 0 | 0 | 1,378 |
4,455,973 | 2010-12-15T23:21:00.000 | 1 | 1 | 0 | 1 | python,root | 4,456,006 | 2 | false | 0 | 0 | Use runuser (or the distro's equvalent) to run it as a different user. runuser does change $HOME, but other similar commands may not. | 2 | 1 | 0 | I have a python script which I would like to launch from inittab, shown below
s1:respawn:/home/a_user/app/script.py
I believe initab executes as root, so the a_user's envrinment is not available
The script needs to know "a_user" home directory for ini file settings and log file storage. I would like to avoid hard coding these paths in my script. Is it possible to execute this script as a_user and not a root? If this is possible would a_user HOME environment variable be available?
Regards | Executing a python script from inittab not as root | 0.099668 | 0 | 0 | 1,378 |
4,455,999 | 2010-12-15T23:25:00.000 | 3 | 1 | 1 | 0 | python,powershell | 4,456,153 | 1 | true | 0 | 0 | I am not sure why you got downvoted as this is a legitimate question. I think the best integration you are going to get trying to integrate PowerShell into CPython will be through spawning a new process and passing in the PowerShell script you want run. Unfortunately this will also mean parsing any output that is generated as well. There is not a COM or C library you can really link against to get much better.
There might be some sort of a general .NET interop library for CPython (I haven't checked), but that may be an option, using that layer you could (at least in theory) use the same techniques as embedding the PowerShell runtime into a regular .NET App. | 1 | 11 | 0 | I know it is possible to use Powershell from within IronPython, but is this possible using CPython beyond using Popen() and other similar calls? I'm trying to do some very basic NET framework programming (windows Forms, etc.) like you can do inside of IronPython using CPython.
Thanks!
Any help appreciated. | Powershell integration with Python (not IronPython) | 1.2 | 0 | 0 | 2,213 |
4,456,444 | 2010-12-16T00:42:00.000 | 1 | 0 | 0 | 0 | python,django,templates,frameworks | 4,456,547 | 1 | true | 1 | 0 | Um... yes?
More seriously - whatever makes you happier. If you're in a hurry, roll your own; if you have a bit more time, by all means get to know the Django system; it'll probably be worthwhile in the longer run. | 1 | 1 | 0 | I'm split between writing my own comments model (pretty easy model, foreign key it to the entry) or using the full-out Django comment framework.
I mean, for right now, I just want a basic box for people to post a comment. That's it. | If I just want a simple comment box below my entry, should I use Django's comment framework or write my own? | 1.2 | 0 | 0 | 477 |
4,456,591 | 2010-12-16T01:14:00.000 | 0 | 0 | 0 | 0 | python,django,django-forms,media | 4,462,233 | 2 | false | 1 | 0 | What happens if you just use {{ form.media }} for each form, and link up the media in the form's Meta? I seem to remember that making sure that it didn't insert anything twice, but it's been a while.
Have you tried that yet? | 1 | 2 | 0 | I send several forms to a template, and I want to put all required media in the <head> tag. Some forms might require the same media (for instance, the same JS file), so I would like to unify all medias before putting them in the <head>. Question is, how do I do that? I know you can unify two medias by doing m1 + m2, but this will look ugly in the generic case where I have an unknown number of forms. Is there some shortcut? | Django: correct way to group a bunch of media's | 0 | 0 | 0 | 135 |
4,458,090 | 2010-12-16T06:34:00.000 | 0 | 1 | 1 | 0 | python,text,encoding,character-encoding,decoding | 14,012,214 | 4 | false | 0 | 0 | Working with xlrd, I have in a line
...xl_data.find(str(cell_value))...
which gives the error:"'ascii' codec can't encode character u'\xdf' in position 3: ordinal not in range(128)".
All suggestions in the forums have been useless for my german words.
But changing into:
...xl_data.find(cell.value)...
gives no error.
So, I suppose using strings as arguments in certain commands with xldr has specific encoding problems. | 1 | 0 | 0 | I have this text in a file - Recuérdame (notice it's a French word). When I read this file with a python script, I get this text as Recuérdame.
I read it as a unicode string. Do I need to find what the encoding of the text is & decode this? or is my terminal playing tricks on me? | Python Text Encoding | 0 | 0 | 0 | 3,875 |
4,458,701 | 2010-12-16T08:24:00.000 | 8 | 0 | 1 | 0 | python,memory,python-idle | 62,961,863 | 4 | false | 0 | 0 | How about dir() which will output instantiated objects as a list? I just used this just now:
[x for x in dir() if x.lower().startswith('y')] | 1 | 53 | 0 | Say that in the python shell (IDLE) I have defined some classes, functions, variables. Also created objects of the classes. Then I deleted some of the objects and created some others. At a later point in time, how can I get to know what are the currently active objects, variables, and methods definitions active in the memory? | How to get the list of all initialized objects and function definitions alive in python? | 1 | 0 | 0 | 51,812 |
4,458,890 | 2010-12-16T08:49:00.000 | 0 | 0 | 1 | 0 | python,database,multithreading,webserver | 4,458,917 | 5 | false | 1 | 0 | If the Web server is single-threaded and DB requests are synchronous (meaning the Web server is blocked while the DB request is being processed) then making it multi-threaded would help.
This would enable you to process multiple requests simultaneously. Your DB engine is probably quite good at that. However, right now you're not letting it to service multiple requests simultaneously because you have the Web server sitting right in front of it that only feeds it one request at a time. | 5 | 4 | 0 | We have a simple webserver for internal use that has only one duty: listen for requests, read them, and push the data in a database. The db and webserver are both located on the same machine. The db is a mysql-db and the server is a python webserver (BaseHTTPServer.HTTPServer) which runs single threaded.
The problem is that two requests can't be handled at the same time. The question is, would it help to make the webserver multi-threaded (using django, cheryypy,..)? Intuitively, the webserver is only performing CPU consuming tasks so changing it to multi-threaded shouldn't help. Is this correct? | Multi threaded webserver vs single threaded | 0 | 0 | 0 | 7,079 |
4,458,890 | 2010-12-16T08:49:00.000 | 0 | 0 | 1 | 0 | python,database,multithreading,webserver | 4,458,945 | 5 | false | 1 | 0 | My instinct says you're right, but it also says that using Django or Cherrypy is WAY overkill, even if you did want to make it multithreaded.
I think you're right, though, since if the webserver really isn't doing anything other than working a DB, then any other thread wouldn't be able to do anything other than start a response. The client will happily wait the ten-to-hundred ms necessary for the other request to finish, and then the server will be able to accept() right away. | 5 | 4 | 0 | We have a simple webserver for internal use that has only one duty: listen for requests, read them, and push the data in a database. The db and webserver are both located on the same machine. The db is a mysql-db and the server is a python webserver (BaseHTTPServer.HTTPServer) which runs single threaded.
The problem is that two requests can't be handled at the same time. The question is, would it help to make the webserver multi-threaded (using django, cheryypy,..)? Intuitively, the webserver is only performing CPU consuming tasks so changing it to multi-threaded shouldn't help. Is this correct? | Multi threaded webserver vs single threaded | 0 | 0 | 0 | 7,079 |
4,458,890 | 2010-12-16T08:49:00.000 | 3 | 0 | 1 | 0 | python,database,multithreading,webserver | 4,458,981 | 5 | false | 1 | 0 | Having several threads or processes will indeed help you (indeed it's in practice required) when you want to handle more than one request at a time.
That doesn't mean that the two requests will be handled faster. Having a pool of processes or threads is very helpful for webserver performance, but that's not really noticeable in cases like this (unless you have multiple cores). But MySQL has no problem handling two requests at the same time, so if your webserver can do it as well, then you get rid of the problem of handling just one request.
But if it's worth the effort to start using such a server only you can answer. :) Django is surely overkill in any case, look at some small WSGI server. | 5 | 4 | 0 | We have a simple webserver for internal use that has only one duty: listen for requests, read them, and push the data in a database. The db and webserver are both located on the same machine. The db is a mysql-db and the server is a python webserver (BaseHTTPServer.HTTPServer) which runs single threaded.
The problem is that two requests can't be handled at the same time. The question is, would it help to make the webserver multi-threaded (using django, cheryypy,..)? Intuitively, the webserver is only performing CPU consuming tasks so changing it to multi-threaded shouldn't help. Is this correct? | Multi threaded webserver vs single threaded | 0.119427 | 0 | 0 | 7,079 |
4,458,890 | 2010-12-16T08:49:00.000 | 0 | 0 | 1 | 0 | python,database,multithreading,webserver | 4,459,115 | 5 | false | 1 | 0 | You should go for multithreaded or asynchronous webserver, otherwise each request is being blocked. Django is a web framework, you might have to look for scripts which you can transparently replace in your current setup and still have your pure python multithreaded webserver. Otherwise twisted is a good solution too. AFA I can see, you may not want a Web Framework because you are not doing a template driven MVC style app. | 5 | 4 | 0 | We have a simple webserver for internal use that has only one duty: listen for requests, read them, and push the data in a database. The db and webserver are both located on the same machine. The db is a mysql-db and the server is a python webserver (BaseHTTPServer.HTTPServer) which runs single threaded.
The problem is that two requests can't be handled at the same time. The question is, would it help to make the webserver multi-threaded (using django, cheryypy,..)? Intuitively, the webserver is only performing CPU consuming tasks so changing it to multi-threaded shouldn't help. Is this correct? | Multi threaded webserver vs single threaded | 0 | 0 | 0 | 7,079 |
4,458,890 | 2010-12-16T08:49:00.000 | 1 | 0 | 1 | 0 | python,database,multithreading,webserver | 4,460,274 | 5 | false | 1 | 0 | Step 1. Use Apache. It may seem like overkill but it's cheap multi-threading with no programming on your part. Apache can be configured to fork off several servers. No programming on your part.
This may be sufficient to make your application run concurrently.
Step 2. Rewrite your application to use the wsgi framework and embed it in the wsgiref server. This won't change much, but it's the way you should always write small web applications.
Step 3. Use mod_wsgi in Apache. It allows you to have one or more background daemon versions of your application. With no additional programming you get a heap of concurrency available to you.
Important lesson learned. Always use WSGI. | 5 | 4 | 0 | We have a simple webserver for internal use that has only one duty: listen for requests, read them, and push the data in a database. The db and webserver are both located on the same machine. The db is a mysql-db and the server is a python webserver (BaseHTTPServer.HTTPServer) which runs single threaded.
The problem is that two requests can't be handled at the same time. The question is, would it help to make the webserver multi-threaded (using django, cheryypy,..)? Intuitively, the webserver is only performing CPU consuming tasks so changing it to multi-threaded shouldn't help. Is this correct? | Multi threaded webserver vs single threaded | 0.039979 | 0 | 0 | 7,079 |
4,459,352 | 2010-12-16T09:49:00.000 | 2 | 0 | 1 | 0 | python,algorithm,qwerty | 4,469,544 | 4 | false | 0 | 0 | I don't have any algorithms to propose, but a few hints:
I use both hands to type, meaning that the keyboard is roughly split in 2 halves, it is frequent that I have coordination issues between the two hands, meaning that each type the letters in the "right" order but the interleaving is wrong. This is especially true if one hand has more letters to type than the other, typical: "the" because the left hand type t and e and the right hand types h.
"slips" are frequent, meaning that often time one is going to miss the key and hit another key instead; "addition" / "deletion" are frequent too, ie typing a supplementary key or not pushing hard enough --> this mean that (obviously) the more letters there is, the harder it is to get the word right.
mix case makes it harder, it requires synchronization between pushing CAPS and hitting the keys, so it's likely that the nearby keys won't have the right upper/lower case.
Hope this helps... | 2 | 13 | 0 | I'm looking for a reasonably simple algorithm to determine how difficult it is to type a word on the QWERTY layout.
The words would not necessarily be dictionary words, so a list of commonly mistyped words or the like is not an option. I'm sure there must be an existing, well-tested algorithm, but I can't find anything.
Can anyone offer any help or advice? I'm coding the algorithm in python, but any other language or pseudo-code is welcome. | Determining how difficult a word is to type on a QWERTY keyboard | 0.099668 | 0 | 0 | 3,967 |
4,459,352 | 2010-12-16T09:49:00.000 | 1 | 0 | 1 | 0 | python,algorithm,qwerty | 4,459,438 | 4 | false | 0 | 0 | Take out your Scrabble set, note down the scores for each letter, total the scores for a word, hey presto you have your algorithm. Not sure it entirely satisfies your requirements, but it might point you in a useful direction. You might, for instance, want to assign scores not only to individual letters but also to di- and tri-grams.
I'm not aware of any existing source of the information you need, perhaps you could come up with your own letter scores by examining the keyboard and assigning higher scores to the more difficult letters: so 1 for 'a', 8 for 'q', 2 for 'm', and so on.
EDIT: I seem to have confused people more than I usually do when I reply on SO. Here's the barebones of my proposal:
a) List all trigrams and digrams which occur in English (or your language). To each of them assign a difficulty-of-typing score. Do the same for individual letters (after all a 4 letter word might be composed of a trigram and a letter rather than two digrams).
b) Score the difficulty of typing a word as the sum of the difficulty of typing its components.
As for the difficulty scores, I haven't a clue, but you could start from 1 for a letter on the home keys on a keyboard, 2 for a letter which uses the index fingers but is not a home key, 3 for a letter which uses the 2nd or 3rd fingers on your hand, and so on. Then for digrams, score low for easy letters on left and right (or right and left) in sequence, high for difficult letters on one hand in sequence (eg qz, though that's perhaps not valid for English). And on you go. | 2 | 13 | 0 | I'm looking for a reasonably simple algorithm to determine how difficult it is to type a word on the QWERTY layout.
The words would not necessarily be dictionary words, so a list of commonly mistyped words or the like is not an option. I'm sure there must be an existing, well-tested algorithm, but I can't find anything.
Can anyone offer any help or advice? I'm coding the algorithm in python, but any other language or pseudo-code is welcome. | Determining how difficult a word is to type on a QWERTY keyboard | 0.049958 | 0 | 0 | 3,967 |
4,460,921 | 2010-12-16T12:49:00.000 | 0 | 0 | 1 | 0 | python,wikipedia | 4,460,959 | 10 | false | 0 | 0 | Try a combination of urllib to fetch the site and BeautifulSoup or lxml to parse the data. | 1 | 42 | 1 | How can I extract the first paragraph from a Wikipedia article, using Python?
For example, for Albert Einstein, that would be:
Albert Einstein (pronounced /ˈælbərt
ˈaɪnstaɪn/; German: [ˈalbɐt ˈaɪnʃtaɪn]
( listen); 14 March 1879 – 18 April
1955) was a theoretical physicist,
philosopher and author who is widely
regarded as one of the most
influential and iconic scientists and
intellectuals of all time. A
German-Swiss Nobel laureate, Einstein
is often regarded as the father of
modern physics.[2] He received the
1921 Nobel Prize in Physics "for his
services to theoretical physics, and
especially for his discovery of the
law of the photoelectric effect".[3] | Extract the first paragraph from a Wikipedia article (Python) | 0 | 0 | 0 | 49,932 |
4,461,191 | 2010-12-16T13:27:00.000 | 1 | 1 | 1 | 0 | ironpython | 4,467,668 | 1 | false | 0 | 0 | You can get the ExceptionOperations object from scriptEngine.GetService(). You can then call FormatException or GetStackFrames. You can also set the ExceptionDetail option to true to get more verbose stack traces from FormatException. | 1 | 2 | 0 | I have an application written in IronPython which uses classes and methods from imported .NET assembly (compiled with debug support). When a method in assembly throws an exception, it gets caught in IronPython code as Exception (not System.Exception) and the traceback ends at last IronPython method.
What I would like to do is to go deeper and append the original CLI traceback after last IronPython method to see where the exception occured inside the assembly.
Is it possible to get original CLI exception from caught IronPython equvivalent or catch it without loosing IronPython's stack trace?
Thanx. | Combine IronPython's and CLI stack trace | 0.197375 | 0 | 0 | 323 |
4,462,068 | 2010-12-16T14:56:00.000 | 0 | 0 | 1 | 0 | python,google-app-engine,printing | 4,462,590 | 4 | false | 0 | 0 | This is just a wild guess, but if item['pubDate'] is a non-string object it might a result of differences between special methods. Perhaps the __str__ method returns nothing, while the __add__ method does something different. | 2 | 2 | 0 | why this does not print anything:
for item in pipe.json["value"]["items"]:
print item["pubDate"]
but this does:
for item in pipe.json["value"]["items"]:
print item["pubDate"] + "\n"
p.s. the loop is running inside another loop.
p.p.s. this is running inside google app engine application.i have looked at http response and it is completely empty in the first case. | weird python print behaviour | 0 | 0 | 0 | 259 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.