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
|
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
744,127 | 2009-04-13T14:48:00.000 | 2 | 0 | 1 | 0 | python,random | 744,170 | 6 | false | 0 | 0 | The random class is quite powerful in python. You can generate a list with the characters desired at the appropriate weights and then use random.choice to obtain a selection.
First, make sure you do an import random.
For example, let's say you wanted a truly random string from A,B,C, or D.
1. Generate a list with the characters
li = ['A','B','C','D']
Then obtain values from it using random.choice
output = "".join([random.choice(li) for i in range(0, n)])
You could easily make that a function with n as a parameter.
In the above case, you have an equal chance of getting A,B,C, or D.
You can use duplicate entries in the list to give characters higher probabilities. So, for example, let's say you wanted a 50% chance of A and 25% chances of B and C respectively. You could have an array like this:
li = ['A','A','B','C']
And so on.
It would not be hard to parameterize the characters coming in with desired weights, to model that I'd use a dictionary.
characterbasis = {'A':25, 'B':25, 'C':25, 'D':25}
Make that the first parameter, and the second being the length of the string and use the above code to generate your string. | 1 | 2 | 0 | For example,
The function could be something like def RandABCD(n, .25, .34, .25, .25):
Where n is the length of the string to be generated and the following numbers are the desired probabilities of A, B, C, D.
I would imagine this is quite simple, however i am having trouble creating a working program. Any help would be greatly appreciated. | I need a Python Function that will output a random string of 4 different characters when given the desired probabilites of the characters | 0.066568 | 0 | 0 | 2,461 |
744,373 | 2009-04-13T16:07:00.000 | 0 | 0 | 1 | 0 | python,circular-dependency,cyclic-reference | 72,349,729 | 14 | false | 0 | 0 | We love to use modules in Python and why not, they provide additional functionalities, better coding practice, and always create a proper structure while using. But many times unknowingly, we can run into python circular import problems if we accidentally have another file named as module’s name. As python prefers importing from the local current directory first and then from site-packages, it will create a circular import problem.
Generally, the Python Circular Import problem occurs when you accidentally name your working file the same as the module name and those modules depend on each other. This way the python opens the same file which causes a circular loop and eventually throws an error.
For example, when you name your file as random.py and try to import “from random import randint”, it’ll throw a circular import error (also termed as from partially initialized module). | 2 | 496 | 0 | What will happen if two modules import each other?
To generalize the problem, what about the cyclic imports in Python? | Circular (or cyclic) imports in Python | 0 | 0 | 0 | 309,185 |
744,373 | 2009-04-13T16:07:00.000 | 417 | 0 | 1 | 0 | python,circular-dependency,cyclic-reference | 746,067 | 14 | false | 0 | 0 | If you do import foo (inside bar.py) and import bar (inside foo.py), it will work fine. By the time anything actually runs, both modules will be fully loaded and will have references to each other.
The problem is when instead you do from foo import abc (inside bar.py) and from bar import xyz (inside foo.py). Because now each module requires the other module to already be imported (so that the name we are importing exists) before it can be imported. | 2 | 496 | 0 | What will happen if two modules import each other?
To generalize the problem, what about the cyclic imports in Python? | Circular (or cyclic) imports in Python | 1 | 0 | 0 | 309,185 |
744,424 | 2009-04-13T16:20:00.000 | 0 | 0 | 0 | 0 | python,django,data-structures,set,unique | 744,439 | 6 | false | 1 | 0 | If the order doesn't matter, use a dict. | 1 | 6 | 0 | I build a list of Django model objects by making several queries. Then I want to remove any duplicates, (all of these objects are of the same type with an auto_increment int PK), but I can't use set() because they aren't hashable.
Is there a quick and easy way to do this? I'm considering using a dict instead of a list with the id as the key. | Django models - how to filter out duplicate values by PK after the fact? | 0 | 0 | 0 | 8,768 |
745,743 | 2009-04-13T23:15:00.000 | 2 | 0 | 1 | 0 | python | 745,745 | 6 | false | 0 | 0 | Yes, Python is interpreted, but you can also run them as long-running applications. | 4 | 38 | 0 | Is Python strictly interpreted at run time, or can it be used to develop programs that run as background applications (like a Java app or C program)? | Is Python interpreted (like Javascript or PHP)? | 0.066568 | 0 | 0 | 20,101 |
745,743 | 2009-04-13T23:15:00.000 | 4 | 0 | 1 | 0 | python | 745,751 | 6 | false | 0 | 0 | Python is an interpreted language but it is the bytecode which is interpreted at run time. There are also many tools out there that can assist you in making your programs run as a windows service / UNIX daemon. | 4 | 38 | 0 | Is Python strictly interpreted at run time, or can it be used to develop programs that run as background applications (like a Java app or C program)? | Is Python interpreted (like Javascript or PHP)? | 0.132549 | 0 | 0 | 20,101 |
745,743 | 2009-04-13T23:15:00.000 | 2 | 0 | 1 | 0 | python | 745,752 | 6 | false | 0 | 0 | Yes, it's interpreted, its main implementation compiles bytecode first and then runs it though (kind of if you took a java source and the JVM compiled it before running it). Still, you can run your application in background. Actually, you can run pretty much anything in background. | 4 | 38 | 0 | Is Python strictly interpreted at run time, or can it be used to develop programs that run as background applications (like a Java app or C program)? | Is Python interpreted (like Javascript or PHP)? | 0.066568 | 0 | 0 | 20,101 |
745,743 | 2009-04-13T23:15:00.000 | 53 | 0 | 1 | 0 | python | 745,749 | 6 | true | 0 | 0 | There's multiple questions here:
No, Python is not interpreted. The standard implementation compiles to bytecode, and then executes in a virtual machine. Many modern JavaScript engines also do this.
Regardless of implementation (interpreter, VM, machine code), anything you want can run in the background. You can run shell scripts in the background, if you want. | 4 | 38 | 0 | Is Python strictly interpreted at run time, or can it be used to develop programs that run as background applications (like a Java app or C program)? | Is Python interpreted (like Javascript or PHP)? | 1.2 | 0 | 0 | 20,101 |
749,937 | 2009-04-15T01:05:00.000 | 0 | 0 | 1 | 0 | python,matplotlib,ip-address,visualization | 749,951 | 4 | false | 0 | 0 | There's a section in the matplotlib user guide about drawing bars on a chart to represent ranges. I've never done that myself but it seems appropriate for what you're looking for. | 1 | 1 | 0 | I've written a little script that collects my external IP address every time I open a new terminal window and appends it, at well as the current time, to a text file. I'm looking for ideas on a way to visualize when/how often my IP address changes. I bounce between home and campus and could separate them using the script, but it would be nice to visualize them separately.
I frequently use matplotlib. Any ideas? | How to visualize IP addresses as they change in python? | 0 | 0 | 0 | 2,072 |
753,749 | 2009-04-15T21:13:00.000 | 2 | 0 | 0 | 1 | python,linux,build | 754,180 | 2 | true | 0 | 0 | You can use the python RPM's linked to from the python home page ChristopheD mentioned.
You can extract the RPM's using cpio, as they are just specialized cpio archives.
Your method of extracting them to your home directory and setting LD_LIBRARY_PATH and PATH should work; I use this all the time for hand-built newer versions of projects I also have installed.
Don't focus on the -devel package though; you need the main package. You can unpack the -devel one as well, but the only thing you'll actually use from it is the libpython2.3.so symlink that points to the actual library, and you can just as well create this by hand.
Whether this is the right approach depends on what you are trying to do. If all you're trying to do is to get this one application to run for you personally, then this hack sounds fine.
If you wanted to actually distribute something to other people for running this application, and you have no way of fixing the actual application, you should consider building an rpm of the older python version that doesn't conflict with the system-installed one. | 1 | 2 | 0 | I am supporting an application with a hard dependency on python-devel 2.3.7. The application runs the python interpreter embedded, attempting to load libpython2.3.so - but since the local machine has libpython2.4.so under /usr/lib64, the application is failing.
I see that there are RPMs for python-devel (but not version 2.3.x). Another wrinkle is that I don't want to overwrite the existing python under /usr/lib (I don't have su anyway). What I want to do is place the somewhere in my home directory (i.e. /home/noahz/lib) and use PATH and LD_LIBRARY_PATH to point to the older version for this application.
What I'm trying to find out (but can't seem to craft the right google search for) is:
1) Where do I download python-devel-2.3 or libpython2.3.so.1.0 (if either available)
2a) If I can't download python-devel-2.3, how do I build libpython2.3.so from source (already downloaded Python-2.3.tgz and
2b) Is building libpython2.3.so.1.0 from source and pointing to it with LD_LIBRARY_PATH good enough, or am I going to run into other problems (other dependencies)
3) In general, am I approaching this problem the right way?
ADDITIONAL INFO:
I attempted to symlink (ln -s) to the later version. This caused the app to fail silently.
Distro is Red Hat Enterprise Linux 5 (RHEL5) - for x86_64 | Need to build (or otherwise obtain) python-devel 2.3 and add to LD_LIBRARY_PATH | 1.2 | 0 | 0 | 1,219 |
755,070 | 2009-04-16T07:20:00.000 | 0 | 0 | 1 | 0 | mod-wsgi,python | 19,104,744 | 2 | false | 0 | 0 | As I understood it last, the idea was to be able to execute multiple applications as well as multiple copies of the same application within the same process.
This is a feature found in other scripting languages (e.g. TCL), and is of particular use to gui builders, web servers, etc.
It breaks in python because many extensions are not multiple-interpreter safe, so one interpreter's actions could affect the variables in another interpreter. | 1 | 18 | 0 | I'm unclear on why the sub-interpreter API exists and why it's used in modules such as the mod_wsgi apache module. Is it mainly used for creating a security sandbox for different applications running within the same process, or is it a way to allow concurrency with multiple threads? Maybe both? Are there other purposes? | What is the purpose of the sub-interpreter API in CPython? | 0 | 0 | 0 | 4,584 |
755,883 | 2009-04-16T12:23:00.000 | 0 | 0 | 1 | 0 | ide,ironpython | 3,078,006 | 9 | false | 0 | 0 | The implementation of the sys module was improved so that you can now utilize CPython’s pdb module in basic scenarios to debug IronPython sessions provided you pass the –X:Frames or –X:FullFrames options to ipy.exe | 1 | 34 | 0 | I am currently learning ironpython and loving but i'm looking to move on from using notepad++ and cmd.exe and try using something with a bit more juice.
I recently learned that iron python studio does not support iron python 2 so that makes my choice a bit more difficult.
Is their any IDE's for windows that would be good iron python 2 development? | IDE for ironpython on windows | 0 | 0 | 0 | 16,827 |
756,630 | 2009-04-16T15:14:00.000 | 0 | 0 | 1 | 1 | python,bash,binary,awk | 6,600,616 | 3 | false | 0 | 0 | In newer versions of Python there exists the bin() function which I believe takes an int and returns a binary literal, of form 0b011010 or whatever. | 1 | 1 | 0 | I am new in binary conversion.
I use Python, Bash and AWK daily.
I would like to see binary conversion's applications in these languages.
For example, I am interested in problems which you solve by it at your work.
Where do you use binary conversion in Python/Bash/AWK?
I would like to see examples of codes. | How do you use Binary conversion in Python/Bash/AWK? | 0 | 0 | 0 | 2,535 |
757,816 | 2009-04-16T20:00:00.000 | 2 | 1 | 0 | 0 | python,performance,postgresql | 758,057 | 2 | false | 0 | 0 | I would think your best bet would be using an external tool, Bonnie++ for example, and parse the program output. Even if you're not that concerned with precision there's no reason to reinvent the wheel. Why rewrite what's already there? | 1 | 1 | 0 | I need to measure the performance of a hard disk using python. What is the best/fastest/shortest/easiest approach to do it? It doesn't have to be overly accurate, just a ballpark value.
My actual goal is to write a small utility which will adjust the postgres settings to the best configuration for the given hardware.
My naive approach would be to write some files and measure the time how long it would take. I would try it for several block sizes, and then I would try to access some random positions within a large file. Any other ideas? | Whats the easiest and fastest way to measure HD performance using Python? | 0.197375 | 0 | 0 | 179 |
759,271 | 2009-04-17T06:37:00.000 | 3 | 0 | 0 | 0 | python,image,cgi | 759,547 | 1 | false | 0 | 1 | You can't remove the file from your cgi script. Because the html page is send to the user only after your script finishes to run. And then the users browser parse the html and fetch the jpg file.
The simplest option is to write the temporary files to a sub directory and periodically clean that directory (living in it the last few minutes only). There are ways to improve this process but they are probably pointless.
A more advanced option (which is also probably pointless, depending on your scenario) is to configure the web server to run a script on the "get jpg" request. And then you can stream the jpg through your script. That way you will know when the jpg was fetched. And in this script you can call a subscript asynchronically to delete the jpg file. | 1 | 2 | 0 | I've written a python CGI script that converts files into .jpgs and displays them in a simple HTML page. I don't want to clutter up the folders with these .jpg files, so I used tempfile.NamedTemporaryFile to create a file to store the converted .jpg output. Everything works great, but i want to remove this file after the page is displayed. Currently I have delete=False set, but i can't seem to remove the file without causing a broken img link. | How can I remove a temporary file (image) that is being displayed by CGI? | 0.53705 | 0 | 0 | 510 |
759,443 | 2009-04-17T07:56:00.000 | 2 | 0 | 1 | 0 | python,subprocess | 1,519,310 | 4 | false | 0 | 0 | The only reliable way I know of is to create a pipe specifically for this purpose. The child will have to repeatedly attempt to read from the pipe, preferably in a non-blocking fashion, or using select. It will get an error when the pipe does not exist anymore (presumably because of the parent's death). | 2 | 11 | 0 | Is there a way for a child process in Python to detect if the parent process has died? | Child process detecting the parent process' death in Python | 0.099668 | 0 | 0 | 5,943 |
759,443 | 2009-04-17T07:56:00.000 | 1 | 0 | 1 | 0 | python,subprocess | 759,455 | 4 | false | 0 | 0 | You might get away with reading your parent process' ID very early in your process, and then checking, but of course that is prone to race conditions. The parent that did the spawn might have died immediately, and even before your process got to execute its first instruction.
Unless you have a way of verifying if a given PID refers to the "expected" parent, I think it's hard to do reliably. | 2 | 11 | 0 | Is there a way for a child process in Python to detect if the parent process has died? | Child process detecting the parent process' death in Python | 0.049958 | 0 | 0 | 5,943 |
759,771 | 2009-04-17T09:39:00.000 | 0 | 0 | 0 | 1 | python,google-app-engine | 760,060 | 4 | false | 1 | 0 | Turns out I needed to do
key = Key.from_path( Application_ModelName, numeric_id )
wasn't clear till i looked at the dict() of an entity | 1 | 3 | 0 | Is it possible to retrieve an entity from google appengine using their numerical IDs and if so how?
I tried using:
key = Key.from_path("ModelName", numericalId)
m = ModelName.get(key)
but the key generated wasnt correct. | How to retrieve google appengine entities using their numerical id? | 0 | 0 | 0 | 1,494 |
760,039 | 2009-04-17T11:17:00.000 | 6 | 1 | 0 | 1 | python,multithreading,debugging,monitoring,pylons | 784,432 | 2 | false | 0 | 0 | As you noted, in --reload mode, Paste sweeps the filesystem every second to see if any of the files loaded have changed. If they have, then Paste reloads the process. You can also manually tell Paste to monitor non-Python code modules for changes if desired.
You can change the reload interval with the --reload-interval option, this will reduce the CPU usage when using --reload as it will sweep less often. | 1 | 6 | 0 | I have a python process (Pylons webapp) that is constantly using 10-30% of CPU. I'll improve/tune logging to get some insight of what's going on, but until then, are there any tools/techniques that allow to see what python process is doing, how many and how busy threads it has etc?
Update:
configured access log which shows that there are no requests going on, webapp is just idling
no point to plug in paste.profile in middleware chain since there are no requests, activity must be happening either in webapp's worker threads or paster web server
running paster like this: "python -m cProfile -o outfile /usr/bin/paster serve dev.ini" and inspecting results shows that most time is spent in "posix.waitpid". Paster runs webapp in subprocess, subprocess activity is not picked up by profiler
looking into ;hacking PasteScript "serve" command so that subprocesses would get profiled
Another update:
After much tinkering, sticking profiler in various places and getting familiar with PasteScript insides, I discovered that the constant CPU load goes away if application is started without "--reload" parameter (this flag tells paster to restart itself if code changes, handy in development), which is fine in production environment. | Investigating python process to see what's eating CPU | 1 | 0 | 0 | 3,282 |
760,310 | 2009-04-17T12:58:00.000 | 0 | 1 | 0 | 0 | python,hardware,mount,dbus,hal | 760,814 | 2 | true | 0 | 0 | Changing the VID/PID might make your device non-usable without custom drivers. HAL isn't supposed to auto-mount your flash drives for you.
That being said, you could always sneak something into the boot sector and/or the beginning part of the drive. There are a lot of spare bytes in there that can be used for custom purposes - both nefarious and otherwise. | 2 | 1 | 0 | I'm trying to find a way to mark a USB flash device in a way that I can programmaticly test for without mounting it or changing the label.
Are there any properties I can modify about a device that will not cause it to behave/look differently to the user?
Running Ubuntu Jaunty. | How to mark a device in a way that can be retrived by HAL but does not require mounting or changing the label | 1.2 | 0 | 0 | 104 |
760,310 | 2009-04-17T12:58:00.000 | 1 | 1 | 0 | 0 | python,hardware,mount,dbus,hal | 760,744 | 2 | false | 0 | 0 | You cannot modify this property, but the tuple (vendor_id, product_id, serial_number) is unique to each device, so you can use this as mark that is already there.
You can enumerate the devices on the USB bus using lsusb or usblib. | 2 | 1 | 0 | I'm trying to find a way to mark a USB flash device in a way that I can programmaticly test for without mounting it or changing the label.
Are there any properties I can modify about a device that will not cause it to behave/look differently to the user?
Running Ubuntu Jaunty. | How to mark a device in a way that can be retrived by HAL but does not require mounting or changing the label | 0.099668 | 0 | 0 | 104 |
761,361 | 2009-04-17T17:22:00.000 | 4 | 0 | 1 | 0 | python,string,unicode,printing | 35,850,273 | 11 | false | 0 | 0 | Just in case you are getting something like this u['hello'] then you must be printing an array. print str(arr[0]) and you are good to go. | 3 | 49 | 0 | Is there a way to globally suppress the unicode string indicator in python? I'm working exclusively with unicode in an application, and do a lot of interactive stuff. Having the u'prefix' show up in all of my debug output is unnecessary and obnoxious. Can it be turned off? | Suppress the u'prefix indicating unicode' in python strings | 0.072599 | 0 | 0 | 77,168 |
761,361 | 2009-04-17T17:22:00.000 | 3 | 0 | 1 | 0 | python,string,unicode,printing | 5,822,501 | 11 | false | 0 | 0 | Not sure with unicode, but generally you can call str.encode() to convert it to a more suitable form. For instance, subprocess output captured in Python 3.0+ captures it as a byte stream (prefix 'b'), and encode() fixes to a regular string form. | 3 | 49 | 0 | Is there a way to globally suppress the unicode string indicator in python? I'm working exclusively with unicode in an application, and do a lot of interactive stuff. Having the u'prefix' show up in all of my debug output is unnecessary and obnoxious. Can it be turned off? | Suppress the u'prefix indicating unicode' in python strings | 0.054491 | 0 | 0 | 77,168 |
761,361 | 2009-04-17T17:22:00.000 | 1 | 0 | 1 | 0 | python,string,unicode,printing | 5,839,420 | 11 | false | 0 | 0 | You have to use print str(your_Variable) | 3 | 49 | 0 | Is there a way to globally suppress the unicode string indicator in python? I'm working exclusively with unicode in an application, and do a lot of interactive stuff. Having the u'prefix' show up in all of my debug output is unnecessary and obnoxious. Can it be turned off? | Suppress the u'prefix indicating unicode' in python strings | 0.01818 | 0 | 0 | 77,168 |
761,824 | 2009-04-17T19:21:00.000 | 2 | 0 | 1 | 0 | python,parsing,markdown | 761,901 | 5 | false | 0 | 0 | Commented and removed it because I finally think I see the rub here: It may be easier to convert your markdown text to HTML and remove HTML from the text. I'm not aware of anything to remove markdown from text effectively but there are many HTML to plain text solutions. | 1 | 44 | 0 | I need to convert markdown text to plain text format to display summary in my website. I want the code in python. | Python : How to convert markdown formatted text to text | 0.07983 | 0 | 0 | 29,331 |
762,111 | 2009-04-17T20:37:00.000 | 3 | 1 | 1 | 0 | python,import | 762,122 | 7 | false | 0 | 0 | python will import from the current directory by default.
sys.path is the variable that controls where python searches for imports. | 2 | 3 | 0 | Is it possible to import modules based on location?
(eg. do all modules i import have to be in /usr/lib64/python2.5/ or a similar dir?)
I'd like to import a module that's local to the current script. | Importing In Python | 0.085505 | 0 | 0 | 462 |
762,111 | 2009-04-17T20:37:00.000 | 0 | 1 | 1 | 0 | python,import | 762,142 | 7 | false | 0 | 0 | It searches in ./lib by default. | 2 | 3 | 0 | Is it possible to import modules based on location?
(eg. do all modules i import have to be in /usr/lib64/python2.5/ or a similar dir?)
I'd like to import a module that's local to the current script. | Importing In Python | 0 | 0 | 0 | 462 |
763,372 | 2009-04-18T12:34:00.000 | 6 | 0 | 0 | 0 | python,linux,vim | 763,426 | 3 | true | 0 | 1 | Write your intermediate results (what you want the user to edit) to a temp file. Then use the $EDITOR environment variable in a system call to make the user edit the temp file, and read the results when the process finishes.
This lets users configure which editor they want to use in a pseudo-standard fashion. | 1 | 1 | 0 | I am writing an editor which has lot of parameters that could be easily interacted with through text. I find it inconvenient to implement a separate text-editor or lots of UI code for every little parameter. Usual buttons, boxes and gadgets would be burdensome and clumsy. I'd much rather let user interact with those parameters through vim.
The preferable way for me would be to get editor open vim with my text buffer. Then, when one would save the text buffer in vim, my editor would get notified from that and update it's view. | How to interact through vim? | 1.2 | 0 | 0 | 300 |
764,312 | 2009-04-18T22:02:00.000 | 1 | 1 | 0 | 0 | python,django,apache,.htaccess,mod-python | 764,769 | 3 | false | 1 | 0 | You're using mod_python wrong. It was never intended to serve python web applications. You should be using WSGI for this... or at least FastCGI. | 1 | 4 | 0 | The host I'm considering for hosting a Django site has mod_python installed, but does not have Django. Django's INSTALL file indicates that I can simply copy the django directory to Python's site-packages directory to install Django, so I suspect that it might be possible to configure Python / mod_python to look for it elsewhere (namely my user space) by modifying sys.path, but I don't know how to change it from .htaccess or mod_python.
How do I modify sys.path from .htaccess to allow mod_python to see Django?
P.S. I can only access the site via FTP (i.e. no shell access). I realize that it sounds like I should just switch hosts, but there are compelling reasons for me to make this work so I'm at least going to try. | How do I modify sys.path from .htaccess to allow mod_python to see Django? | 0.066568 | 0 | 0 | 1,417 |
764,631 | 2009-04-19T01:35:00.000 | 1 | 0 | 1 | 1 | python,console,hide | 70,466,855 | 9 | false | 0 | 0 | just change the file extension from .py to .pyw | 3 | 92 | 0 | I am writing an IRC bot in Python.
I wish to make stand-alone binaries for Linux and Windows of it. And mainly I wish that when the bot initiates, the console window should hide and the user should not be able to see the window.
What can I do for that? | How to hide console window in python? | 0.022219 | 0 | 0 | 193,952 |
764,631 | 2009-04-19T01:35:00.000 | 44 | 0 | 1 | 1 | python,console,hide | 764,642 | 9 | false | 0 | 0 | In linux, just run it, no problem. In Windows, you want to use the pythonw executable.
Update
Okay, if I understand the question in the comments, you're asking how to make the command window in which you've started the bot from the command line go away afterwards?
UNIX (Linux)
$ nohup mypythonprog &
Windows
C:/> start pythonw mypythonprog
I think that's right. In any case, now you can close the terminal. | 3 | 92 | 0 | I am writing an IRC bot in Python.
I wish to make stand-alone binaries for Linux and Windows of it. And mainly I wish that when the bot initiates, the console window should hide and the user should not be able to see the window.
What can I do for that? | How to hide console window in python? | 1 | 0 | 0 | 193,952 |
764,631 | 2009-04-19T01:35:00.000 | 28 | 0 | 1 | 1 | python,console,hide | 15,148,338 | 9 | false | 0 | 0 | On Unix Systems (including GNU/Linux, macOS, and BSD)
Use nohup mypythonprog &, and you can close the terminal window without disrupting the process. You can also run exit if you are running in the cloud and don't want to leave a hanging shell process.
On Windows Systems
Save the program with a .pyw extension and now it will open with pythonw.exe. No shell window.
For example, if you have foo.py, you need to rename it to foo.pyw. | 3 | 92 | 0 | I am writing an IRC bot in Python.
I wish to make stand-alone binaries for Linux and Windows of it. And mainly I wish that when the bot initiates, the console window should hide and the user should not be able to see the window.
What can I do for that? | How to hide console window in python? | 1 | 0 | 0 | 193,952 |
764,778 | 2009-04-19T03:24:00.000 | 5 | 1 | 0 | 0 | python,smtplib,ssmtp | 765,044 | 3 | true | 0 | 0 | In a Python program, there is no advantage.
The only purpose of ssmtp is to wrap the SMTP protocol in the sendmail API. That is, it provides a program /usr/sbin/sendmail that accepts the same options, arguments, and inputs as the full-blown sendmail (though most of the options do nothing); but behind the scenes, instead of processing the email itself, it sends the message to an SMTP server. This is for systems that need to have a sendmail program present, perhaps because they don't understand SMTP - for example, I think older versions of PHP had this requirement, and even in recent versions it might still be easier to configure PHP to use the so-called sendmail interface (i.e. the program sendmail) than to use SMTP directly. (I haven't used PHP in a little while, I'm not sure about the current status)
However, in Python the situation is reversed: you have a builtin library that makes it easy to use SMTP directly, whereas using sendmail requires you to invoke the subprocess module which is somewhat clunky and also very dependent on things that are not part of Python. So basically there is no reason not to use smtplib. | 2 | 3 | 0 | I need to send email in delbian linux. How to send? I run my server on 256 MB linux box and I heard postfix and sendmail is overkill.
Recently I came across the ssmtp, that seems to be an executable, needs to be executed as a process and called through python using os modules.
alternatively, python already provides smtplib which is working fine with me.
What is the advantage of using ssmtp over python's smtplib? | how to send mail in python ssmtp vs smtplib | 1.2 | 0 | 0 | 4,757 |
764,778 | 2009-04-19T03:24:00.000 | 2 | 1 | 0 | 0 | python,smtplib,ssmtp | 766,413 | 3 | false | 0 | 0 | Additionally, postfix is very easy to install in "satellite" mode, where all it does is queue and deliver email for you. Way easier than implementing your own email queue. Most decent package management systems will let you configure it this way. | 2 | 3 | 0 | I need to send email in delbian linux. How to send? I run my server on 256 MB linux box and I heard postfix and sendmail is overkill.
Recently I came across the ssmtp, that seems to be an executable, needs to be executed as a process and called through python using os modules.
alternatively, python already provides smtplib which is working fine with me.
What is the advantage of using ssmtp over python's smtplib? | how to send mail in python ssmtp vs smtplib | 0.132549 | 0 | 0 | 4,757 |
765,797 | 2009-04-19T18:00:00.000 | 1 | 0 | 1 | 0 | python,datetime,timedelta | 3,260,826 | 21 | false | 0 | 0 | In the end what you have is a maths issue. If every 4 years we have an extra day lets then dived the timedelta in days, not by 365 but 365*4 + 1, that would give you the amount of 4 years. Then divide it again by 4.
timedelta / ((365*4) +1) / 4 = timedelta * 4 / (365*4 +1) | 4 | 172 | 0 | I need to check if some number of years have been since some date. Currently I've got timedelta from datetime module and I don't know how to convert it to years. | Convert timedelta to years? | 0.009524 | 0 | 0 | 196,787 |
765,797 | 2009-04-19T18:00:00.000 | 5 | 0 | 1 | 0 | python,datetime,timedelta | 765,804 | 21 | false | 0 | 0 | How exact do you need it to be? td.days / 365.25 will get you pretty close, if you're worried about leap years. | 4 | 172 | 0 | I need to check if some number of years have been since some date. Currently I've got timedelta from datetime module and I don't know how to convert it to years. | Convert timedelta to years? | 0.047583 | 0 | 0 | 196,787 |
765,797 | 2009-04-19T18:00:00.000 | 57 | 0 | 1 | 0 | python,datetime,timedelta | 765,862 | 21 | false | 0 | 0 | If you're trying to check if someone is 18 years of age, using timedelta will not work correctly on some edge cases because of leap years. For example, someone born on January 1, 2000, will turn 18 exactly 6575 days later on January 1, 2018 (5 leap years included), but someone born on January 1, 2001, will turn 18 exactly 6574 days later on January 1, 2019 (4 leap years included). Thus, you if someone is exactly 6574 days old, you can't determine if they are 17 or 18 without knowing a little more information about their birthdate.
The correct way to do this is to calculate the age directly from the dates, by subtracting the two years, and then subtracting one if the current month/day precedes the birth month/day. | 4 | 172 | 0 | I need to check if some number of years have been since some date. Currently I've got timedelta from datetime module and I don't know how to convert it to years. | Convert timedelta to years? | 1 | 0 | 0 | 196,787 |
765,797 | 2009-04-19T18:00:00.000 | 7 | 0 | 1 | 0 | python,datetime,timedelta | 1,959,782 | 21 | false | 0 | 0 | Get the number of days, then divide by 365.2425 (the mean Gregorian year) for years. Divide by 30.436875 (the mean Gregorian month) for months. | 4 | 172 | 0 | I need to check if some number of years have been since some date. Currently I've got timedelta from datetime module and I don't know how to convert it to years. | Convert timedelta to years? | 1 | 0 | 0 | 196,787 |
765,964 | 2009-04-19T19:51:00.000 | 1 | 0 | 0 | 0 | python,django,amazon-web-services,amazon-s3 | 766,030 | 4 | false | 1 | 0 | You will have to build the whole access logic to S3 in your applications | 3 | 10 | 0 | Trying to understand S3...How do you limit access to a file you upload to S3? For example, from a web application, each user has files they can upload, but how do you limit access so only that user has access to that file? It seems like the query string authentication requires an expiration date and that won't work for me, is there another way to do this? | Amazon S3 permissions | 0.049958 | 1 | 1 | 4,305 |
765,964 | 2009-04-19T19:51:00.000 | 8 | 0 | 0 | 0 | python,django,amazon-web-services,amazon-s3 | 768,090 | 4 | false | 1 | 0 | Have the user hit your server
Have the server set up a query-string authentication with a short expiration (minutes, hours?)
Have your server redirect to #2 | 3 | 10 | 0 | Trying to understand S3...How do you limit access to a file you upload to S3? For example, from a web application, each user has files they can upload, but how do you limit access so only that user has access to that file? It seems like the query string authentication requires an expiration date and that won't work for me, is there another way to do this? | Amazon S3 permissions | 1 | 1 | 1 | 4,305 |
765,964 | 2009-04-19T19:51:00.000 | 14 | 0 | 0 | 0 | python,django,amazon-web-services,amazon-s3 | 768,050 | 4 | false | 1 | 0 | There are various ways to control access to the S3 objects:
Use the query string auth - but as you noted this does require an expiration date. You could make it far in the future, which has been good enough for most things I have done.
Use the S3 ACLS - but this requires the user to have an AWS account and authenticate with AWS to access the S3 object. This is probably not what you are looking for.
You proxy the access to the S3 object through your application, which implements your access control logic. This will bring all the bandwidth through your box.
You can set up an EC2 instance with your proxy logic - this keeps the bandwidth closer to S3 and can reduce latency in certain situations. The difference between this and #3 could be minimal, but depends your particular situation. | 3 | 10 | 0 | Trying to understand S3...How do you limit access to a file you upload to S3? For example, from a web application, each user has files they can upload, but how do you limit access so only that user has access to that file? It seems like the query string authentication requires an expiration date and that won't work for me, is there another way to do this? | Amazon S3 permissions | 1 | 1 | 1 | 4,305 |
766,372 | 2009-04-19T23:24:00.000 | 0 | 0 | 1 | 0 | python,regex,regex-greedy | 58,570,414 | 7 | false | 0 | 0 | To start with, I do not suggest using "*" in regexes. Yes, I know, it is the most used multi-character delimiter, but it is nevertheless a bad idea. This is because, while it does match any amount of repetition for that character, "any" includes 0, which is usually something you want to throw a syntax error for, not accept. Instead, I suggest using the + sign, which matches any repetition of length > 1. What's more, from what I can see, you are dealing with fixed-length parenthesized expressions. As a result, you can probably use the {x, y} syntax to specifically specify the desired length.
However, if you really do need non-greedy repetition, I suggest consulting the all-powerful ?. This, when placed after at the end of any regex repetition specifier, will force that part of the regex to find the least amount of text possible.
That being said, I would be very careful with the ? as it, like the Sonic Screwdriver in Dr. Who, has a tendency to do, how should I put it, "slightly" undesired things if not carefully calibrated. For example, to use your example input, it would identify ((1) (note the lack of a second rparen) as a match. | 3 | 218 | 0 | How do I make a python regex like "(.*)" such that, given "a (b) c (d) e" python matches "b" instead of "b) c (d"?
I know that I can use "[^)]" instead of ".", but I'm looking for a more general solution that keeps my regex a little cleaner. Is there any way to tell python "hey, match this as soon as possible"? | Python non-greedy regexes | 0 | 0 | 0 | 140,869 |
766,372 | 2009-04-19T23:24:00.000 | 6 | 0 | 1 | 0 | python,regex,regex-greedy | 773,844 | 7 | false | 0 | 0 | As the others have said using the ? modifier on the * quantifier will solve your immediate problem, but be careful, you are starting to stray into areas where regexes stop working and you need a parser instead. For instance, the string "(foo (bar)) baz" will cause you problems. | 3 | 218 | 0 | How do I make a python regex like "(.*)" such that, given "a (b) c (d) e" python matches "b" instead of "b) c (d"?
I know that I can use "[^)]" instead of ".", but I'm looking for a more general solution that keeps my regex a little cleaner. Is there any way to tell python "hey, match this as soon as possible"? | Python non-greedy regexes | 1 | 0 | 0 | 140,869 |
766,372 | 2009-04-19T23:24:00.000 | 16 | 0 | 1 | 0 | python,regex,regex-greedy | 766,379 | 7 | false | 0 | 0 | Would not \\(.*?\\) work? That is the non-greedy syntax. | 3 | 218 | 0 | How do I make a python regex like "(.*)" such that, given "a (b) c (d) e" python matches "b" instead of "b) c (d"?
I know that I can use "[^)]" instead of ".", but I'm looking for a more general solution that keeps my regex a little cleaner. Is there any way to tell python "hey, match this as soon as possible"? | Python non-greedy regexes | 1 | 0 | 0 | 140,869 |
766,636 | 2009-04-20T02:21:00.000 | 4 | 0 | 1 | 0 | python,deployment,python-3.x | 766,644 | 12 | false | 0 | 0 | Compiled 3rd party modules haven't updated.
Different syntax
Slower integers.
The #python IRC channel on freenode has in its title that its too early to switch. | 11 | 18 | 0 | I ask this for deployable reasons. As in, if I write a solution in python, I feel bound to write to 2.x due to the lack of adoption of python 3. This is a major daily concern of mine, and I want to figure out what's going on.
For many of the python-based questions here, people are giving solutions that simply do not work in python 3.x.
So, I ask the question: What has prevented you from switching to python 3.x in your personal or work environment? The conversion script exists, and yet programmers (who are usually the earliest adopters of everything) seem to refuse to upgrade.
Why? | Why won't you switch to Python 3.x? | 0.066568 | 0 | 0 | 5,241 |
766,636 | 2009-04-20T02:21:00.000 | 18 | 0 | 1 | 0 | python,deployment,python-3.x | 766,656 | 12 | false | 0 | 0 | Because major libraries that my codebase depends upon have not released a 3.x version. (wxPython, matplotlib, numpy, etc.)
So the responsibility goes upstream from my point of view.
If all my dependencies were 3.x compatible, I'd probably have switched by now. | 11 | 18 | 0 | I ask this for deployable reasons. As in, if I write a solution in python, I feel bound to write to 2.x due to the lack of adoption of python 3. This is a major daily concern of mine, and I want to figure out what's going on.
For many of the python-based questions here, people are giving solutions that simply do not work in python 3.x.
So, I ask the question: What has prevented you from switching to python 3.x in your personal or work environment? The conversion script exists, and yet programmers (who are usually the earliest adopters of everything) seem to refuse to upgrade.
Why? | Why won't you switch to Python 3.x? | 1 | 0 | 0 | 5,241 |
766,636 | 2009-04-20T02:21:00.000 | 1 | 0 | 1 | 0 | python,deployment,python-3.x | 767,568 | 12 | false | 0 | 0 | Because the default installation of 2.5 on Mac OSX Leopard works just fine. I have no need to upgrade and I see no advantage to upgrading except an end to the woes of unicode. | 11 | 18 | 0 | I ask this for deployable reasons. As in, if I write a solution in python, I feel bound to write to 2.x due to the lack of adoption of python 3. This is a major daily concern of mine, and I want to figure out what's going on.
For many of the python-based questions here, people are giving solutions that simply do not work in python 3.x.
So, I ask the question: What has prevented you from switching to python 3.x in your personal or work environment? The conversion script exists, and yet programmers (who are usually the earliest adopters of everything) seem to refuse to upgrade.
Why? | Why won't you switch to Python 3.x? | 0.016665 | 0 | 0 | 5,241 |
766,636 | 2009-04-20T02:21:00.000 | 4 | 0 | 1 | 0 | python,deployment,python-3.x | 766,686 | 12 | false | 0 | 0 | 3rd party tools and libraries. I'm having trouble making some things work under 2.6 (not a LOT of trouble, mind you, but some.)
As I see it, the ecosystem is one of Python's biggest strengths, and going to 3.0 at this point chucks a lot of that out the window. (In a year, I'm sure the story will be totally different.)
(Obviously, there's a chicken and egg problem here, but fortunately it's not my problem to solve, so I'll stay with 2.6 for a while.) | 11 | 18 | 0 | I ask this for deployable reasons. As in, if I write a solution in python, I feel bound to write to 2.x due to the lack of adoption of python 3. This is a major daily concern of mine, and I want to figure out what's going on.
For many of the python-based questions here, people are giving solutions that simply do not work in python 3.x.
So, I ask the question: What has prevented you from switching to python 3.x in your personal or work environment? The conversion script exists, and yet programmers (who are usually the earliest adopters of everything) seem to refuse to upgrade.
Why? | Why won't you switch to Python 3.x? | 0.066568 | 0 | 0 | 5,241 |
766,636 | 2009-04-20T02:21:00.000 | 3 | 0 | 1 | 0 | python,deployment,python-3.x | 766,648 | 12 | false | 0 | 0 | For many of the python-based questions here, people are giving solutions that simply do not work in python 3.x.
I think you answered your own question here. The lack of backwards compatibility makes 3.0 a much harder sell than a seamless upgrade because you have to adjust your thinking and discard some programming techniques to use the new version.
Call me back when they have an upgrade script for my brain. | 11 | 18 | 0 | I ask this for deployable reasons. As in, if I write a solution in python, I feel bound to write to 2.x due to the lack of adoption of python 3. This is a major daily concern of mine, and I want to figure out what's going on.
For many of the python-based questions here, people are giving solutions that simply do not work in python 3.x.
So, I ask the question: What has prevented you from switching to python 3.x in your personal or work environment? The conversion script exists, and yet programmers (who are usually the earliest adopters of everything) seem to refuse to upgrade.
Why? | Why won't you switch to Python 3.x? | 0.049958 | 0 | 0 | 5,241 |
766,636 | 2009-04-20T02:21:00.000 | 1 | 0 | 1 | 0 | python,deployment,python-3.x | 767,769 | 12 | false | 0 | 0 | If you are interested to move to Py3k one interesting way would be to write code in Py3k and use a 3to2 script which is being written now as a part of Google Summer of code project, on the lines of 2to3 script. | 11 | 18 | 0 | I ask this for deployable reasons. As in, if I write a solution in python, I feel bound to write to 2.x due to the lack of adoption of python 3. This is a major daily concern of mine, and I want to figure out what's going on.
For many of the python-based questions here, people are giving solutions that simply do not work in python 3.x.
So, I ask the question: What has prevented you from switching to python 3.x in your personal or work environment? The conversion script exists, and yet programmers (who are usually the earliest adopters of everything) seem to refuse to upgrade.
Why? | Why won't you switch to Python 3.x? | 0.016665 | 0 | 0 | 5,241 |
766,636 | 2009-04-20T02:21:00.000 | 1 | 0 | 1 | 0 | python,deployment,python-3.x | 6,590,680 | 12 | false | 0 | 0 | The main reason I am not switching is that so many books and coding challenge websites are still 2.x. I installed 3.x and realized very quickly that I had to uninstall and go to 2.x. | 11 | 18 | 0 | I ask this for deployable reasons. As in, if I write a solution in python, I feel bound to write to 2.x due to the lack of adoption of python 3. This is a major daily concern of mine, and I want to figure out what's going on.
For many of the python-based questions here, people are giving solutions that simply do not work in python 3.x.
So, I ask the question: What has prevented you from switching to python 3.x in your personal or work environment? The conversion script exists, and yet programmers (who are usually the earliest adopters of everything) seem to refuse to upgrade.
Why? | Why won't you switch to Python 3.x? | 0.016665 | 0 | 0 | 5,241 |
766,636 | 2009-04-20T02:21:00.000 | 0 | 0 | 1 | 0 | python,deployment,python-3.x | 979,900 | 12 | false | 0 | 0 | Because of the lack of backward compatibility, switching is hard, especially if there is C code involved. And although I understand the unicode/string thing may be very useful to some people, I certainly don't care about it myself.
Basically, Py3k did not solve many problem that I care about (distribution issues, versioning of modules, simplified import model). | 11 | 18 | 0 | I ask this for deployable reasons. As in, if I write a solution in python, I feel bound to write to 2.x due to the lack of adoption of python 3. This is a major daily concern of mine, and I want to figure out what's going on.
For many of the python-based questions here, people are giving solutions that simply do not work in python 3.x.
So, I ask the question: What has prevented you from switching to python 3.x in your personal or work environment? The conversion script exists, and yet programmers (who are usually the earliest adopters of everything) seem to refuse to upgrade.
Why? | Why won't you switch to Python 3.x? | 0 | 0 | 0 | 5,241 |
766,636 | 2009-04-20T02:21:00.000 | 1 | 0 | 1 | 0 | python,deployment,python-3.x | 979,881 | 12 | false | 0 | 0 | Unfortunately, for the same reason as most others have said - 3rd party libraries still not having been made 3.0 compatible.
For this reason, as well as that some GNU/Linux distributions (Ubuntu in my case) still comes with Python 2.6, I can't completely throw 2.x out the window yet.
However, the change to 3.0 is not a major one IMO. Except for "print" being a function and the new string formatting system, it's really more or less the same as before.
In fact, I find that most of my old scripts (those that do not depend on 3.0 incompatible 3rd party libraries) will work flawlessly in 3.0 after I update all the prints and string formatting. In some cases I've also had to change some module names (specifically stuff from the "email" module), but other than that nothing major.
Also, all the scripts I have updated for 3.x compatibility so far still seem to work flawlessly in 2.6 (but not older 2.x of course, as they lack the new 3.x syntax). | 11 | 18 | 0 | I ask this for deployable reasons. As in, if I write a solution in python, I feel bound to write to 2.x due to the lack of adoption of python 3. This is a major daily concern of mine, and I want to figure out what's going on.
For many of the python-based questions here, people are giving solutions that simply do not work in python 3.x.
So, I ask the question: What has prevented you from switching to python 3.x in your personal or work environment? The conversion script exists, and yet programmers (who are usually the earliest adopters of everything) seem to refuse to upgrade.
Why? | Why won't you switch to Python 3.x? | 0.016665 | 0 | 0 | 5,241 |
766,636 | 2009-04-20T02:21:00.000 | 1 | 0 | 1 | 0 | python,deployment,python-3.x | 768,000 | 12 | false | 0 | 0 | The operating system I use the most, Debian, does not have a Python 3 package, not even in the "unstable" (brand new) branch. Unless I compile it myself (which is quite 20th century), it means no Python3 to me.
I bet it is the same issue with many operating systems. | 11 | 18 | 0 | I ask this for deployable reasons. As in, if I write a solution in python, I feel bound to write to 2.x due to the lack of adoption of python 3. This is a major daily concern of mine, and I want to figure out what's going on.
For many of the python-based questions here, people are giving solutions that simply do not work in python 3.x.
So, I ask the question: What has prevented you from switching to python 3.x in your personal or work environment? The conversion script exists, and yet programmers (who are usually the earliest adopters of everything) seem to refuse to upgrade.
Why? | Why won't you switch to Python 3.x? | 0.016665 | 0 | 0 | 5,241 |
766,636 | 2009-04-20T02:21:00.000 | 0 | 0 | 1 | 0 | python,deployment,python-3.x | 6,590,823 | 12 | false | 0 | 0 | Python 3+ does not support numpy.
Correction: it now does. As it now supports mathplotlib. | 11 | 18 | 0 | I ask this for deployable reasons. As in, if I write a solution in python, I feel bound to write to 2.x due to the lack of adoption of python 3. This is a major daily concern of mine, and I want to figure out what's going on.
For many of the python-based questions here, people are giving solutions that simply do not work in python 3.x.
So, I ask the question: What has prevented you from switching to python 3.x in your personal or work environment? The conversion script exists, and yet programmers (who are usually the earliest adopters of everything) seem to refuse to upgrade.
Why? | Why won't you switch to Python 3.x? | 0 | 0 | 0 | 5,241 |
767,212 | 2009-04-20T07:11:00.000 | 6 | 0 | 0 | 1 | python,windows,events,operating-system,screenshot | 767,992 | 4 | false | 0 | 1 | There will certainly be no protection against a screenshot taken with a digital camera. | 2 | 0 | 0 | There are various ways to take screenshots of a running application in Windows. However, I hear that an application can be tailored such that it can notice when a screenshot is being taken of it, through some windows event handlers perhaps? Is there any way of taking a screenshot such that it is impossible for the application to notice? (Maybe even running the application inside a VM, and taking a screenshot from the host?) I'd prefer solutions in Python, but anything will do. | Programmatically taking screenshots in windows without the application noticing | 1 | 0 | 0 | 3,194 |
767,212 | 2009-04-20T07:11:00.000 | 3 | 0 | 0 | 1 | python,windows,events,operating-system,screenshot | 767,985 | 4 | true | 0 | 1 | > I hear that an application can be tailored such that it can notice when a screenshot is being taken of it
Complete nonsense.
Don't repeat what kids say...
Read MSDN about screenshots. | 2 | 0 | 0 | There are various ways to take screenshots of a running application in Windows. However, I hear that an application can be tailored such that it can notice when a screenshot is being taken of it, through some windows event handlers perhaps? Is there any way of taking a screenshot such that it is impossible for the application to notice? (Maybe even running the application inside a VM, and taking a screenshot from the host?) I'd prefer solutions in Python, but anything will do. | Programmatically taking screenshots in windows without the application noticing | 1.2 | 0 | 0 | 3,194 |
767,519 | 2009-04-20T09:14:00.000 | 0 | 1 | 1 | 0 | python,ruby,lambda | 768,265 | 4 | false | 0 | 0 | The def is equivalent of an assignment statement which only binds the function object to the object reference variable.
The object reference variable can then be used to call the function object to execute. | 1 | 10 | 0 | Can you elaborate on the current state of "blocks" (in the Ruby sense) in Python?
What are the language constructs that exist in Python? How do they compare to other languages (like Ruby, Smalltalk, [insert more])? Or does Python lack such constructs?
I have so far understood the lambda thing; it is only one-line, but maybe it comes close. What about "decorators" and yield in this context?
I am also using old Python versions in some projects. Which constructs were introduced in which Python version (2.5, 2.6, etc.) or are planned in future versions?
Can you link interesting articles on the subject that explain this stuff for Python and also comparing to other languages and could be interesting for someone who wants to extend basic Python knowledge? | Blocks of code in Python | 0 | 0 | 0 | 4,121 |
767,684 | 2009-04-20T10:23:00.000 | 3 | 1 | 0 | 1 | python,zip,time-estimation | 767,701 | 4 | false | 0 | 0 | I suggest you measure the average time it takes to produce a zip of a certain size. Then you calculate the estimate from that measure. However I think the estimate will be very rough in any case if you don't know how well the data compresses. If the data you want to compress had a very similar "profile" each time you could probably make better predictions. | 2 | 7 | 0 | I need to create ZIP archives on demand, using either Python zipfile module or unix command line utilities.
Resources to be zipped are often > 1GB and not necessarily compression-friendly.
How do I efficiently estimate its creation time / size? | Estimating zip size/creation time | 0.148885 | 0 | 0 | 3,583 |
767,684 | 2009-04-20T10:23:00.000 | 16 | 1 | 0 | 1 | python,zip,time-estimation | 767,704 | 4 | true | 0 | 0 | Extract a bunch of small parts from the big file. Maybe 64 chunks of 64k each. Randomly selected.
Concatenate the data, compress it, measure the time and the compression ratio. Since you've randomly selected parts of the file chances are that you have compressed a representative subset of the data.
Now all you have to do is to estimate the time for the whole file based on the time of your test-data. | 2 | 7 | 0 | I need to create ZIP archives on demand, using either Python zipfile module or unix command line utilities.
Resources to be zipped are often > 1GB and not necessarily compression-friendly.
How do I efficiently estimate its creation time / size? | Estimating zip size/creation time | 1.2 | 0 | 0 | 3,583 |
769,175 | 2009-04-20T16:57:00.000 | 0 | 0 | 0 | 0 | python,gtk,pygtk,x11 | 1,030,408 | 5 | false | 0 | 1 | Not having received a "this is how to do this" answer and having done a bit more research I can say that -- as far as I know -- there is no easy way to achieve this sort of functionality with PyGTK. The best options are to set window manager hints and leave it up to the WM to do what you want (hopefully). | 3 | 1 | 0 | Is there a way to force a gtk.Window object to ignore the Window Manager's show/hide commands, such as "iconify" and "show desktop?"
I'm trying to create a persistent window, stuck to the desktop, that will not disappear with all other windows when the desktop is exposed.
EDIT: I guess what I'm wondering specifically is whether or not it's possible to reproduce the behavior found in applications such as docks, desktop widgets, system trays, etc. using PyGTK? | Persistent Windows in PyGTK | 0 | 0 | 0 | 1,034 |
769,175 | 2009-04-20T16:57:00.000 | 0 | 0 | 0 | 0 | python,gtk,pygtk,x11 | 5,474,070 | 5 | false | 0 | 1 | I think gtk_window_set_type_hint(window, GDK_WINDOW_TYPE_HINT_SPLASHSCREEN) is what you want. It is also GDK_WINDOW_TYPE_HINT_DOCK, but then the window stay on top of all, and you can't send it back. | 3 | 1 | 0 | Is there a way to force a gtk.Window object to ignore the Window Manager's show/hide commands, such as "iconify" and "show desktop?"
I'm trying to create a persistent window, stuck to the desktop, that will not disappear with all other windows when the desktop is exposed.
EDIT: I guess what I'm wondering specifically is whether or not it's possible to reproduce the behavior found in applications such as docks, desktop widgets, system trays, etc. using PyGTK? | Persistent Windows in PyGTK | 0 | 0 | 0 | 1,034 |
769,175 | 2009-04-20T16:57:00.000 | 2 | 0 | 0 | 0 | python,gtk,pygtk,x11 | 771,431 | 5 | true | 0 | 1 | You've got it backwards; it's not the window manager telling the window to minimize, by sending it a command. The window manager owns the window, if it wants to stop mapping a window, it will just do it, without asking the window for permission.
So I would think that the answer is "no". | 3 | 1 | 0 | Is there a way to force a gtk.Window object to ignore the Window Manager's show/hide commands, such as "iconify" and "show desktop?"
I'm trying to create a persistent window, stuck to the desktop, that will not disappear with all other windows when the desktop is exposed.
EDIT: I guess what I'm wondering specifically is whether or not it's possible to reproduce the behavior found in applications such as docks, desktop widgets, system trays, etc. using PyGTK? | Persistent Windows in PyGTK | 1.2 | 0 | 0 | 1,034 |
769,766 | 2009-04-20T19:27:00.000 | 0 | 1 | 1 | 0 | python,setuptools,distutils,egg | 1,000,651 | 1 | false | 0 | 0 | We're solving something similar, ability to use setup.py develop if You're mere user without access to global site-packages. So far, we solved it with virtualenv.
I'd say it will help for your case too: have minimal system-wide install (or explicitly exclude it), create virtual environment with eggs you want and test there.
(Or, for integration tests, create clean environment, install egg and test all dependencies are installed).
For 2, I'm not sure, but it should work too, with multiple virtualenvs. For 3, setup.py develop is the way to go. | 1 | 0 | 0 | I would like to use the entry point functionality in setuptools.
There are a number of occasions where I would like to tightly control the list of eggs that are run, and thence the extensions that contribute to a set of entry points:
egg integration testing, where I want to run multiple test suites on different combinations of eggs.
scanning a single directory of eggs/plugins so as to run two different instances of the same program, but with different eggs.
development time, where I am developing one or more egg, and would like to run the program as part of the normal edit-run cycle.
I have looked through the setuptools documentation, and while it doesn't say that this is not possible, I must have missed something saying how to do it.
What is the best way to approach deploying plugins differently to the default system-wide discovery? | How do I load entry-points for a defined set of eggs with Python setuptools? | 0 | 0 | 0 | 294 |
770,385 | 2009-04-20T22:39:00.000 | 1 | 0 | 0 | 1 | python,google-app-engine,import | 771,165 | 1 | true | 1 | 0 | Strange.
I would start troubleshooting by making 100% sure that the sys.path that dev_appserver.py uses does include C:\Python25\Lib\site-packages\gaeutilities-1.2.1.
I suggest you display sys.path in a HTML view served by dev_appserver.py.
Check permissions on gaeutilities-1.2.1 directory and subdirectories. Perhaps the python interpreter is unable to create *.pyc files or something like that.
Another suggestion:
Put the appengines_utilities folder in your application directory (the directory that contains your app.yaml file). I guess you need all third-party stuff there anyway if you want to upload the code to google's servers. | 1 | 0 | 0 | I'm developing a gae application on a windows machine. to have session handling I downloaded gaeutilities and added its path (C:\Python25\Lib\site-packages\gaeutilities-1.2.1) to the registry ("PythonPath" item under python25).
in my code this is how I import the gaeutilities Session class:
from appengine_utilities.sessions import Session
when gae engine (dev_appserver.py) tries to import it, an exception is raised, stating an importerror and "no module named appengine_utilities.sessions"
on the other hand, pyscripter can find the module (autocomplete becomes available for the Session class), and I can import the module within the python interpreter (the same one that dev_appserver uses, python 2.5.4).
for a remedy, I created a PYTHONPATH environmental variable and also added the path to it. nothing changes.
I'm lost. what am I doing wrong?
important edit: I have found myself to be totally unable to import any 3rd party gae modules. PYTHONPATH is correct, sys.path is correct, registry is correct, still dev_appserver complains of importerror. | importing gaeutilities or any other module by dev_appserver | 1.2 | 0 | 0 | 803 |
770,427 | 2009-04-20T23:00:00.000 | 0 | 0 | 0 | 0 | python,django | 771,066 | 2 | false | 1 | 0 | Have the user submit a POST request to delete that model instance. These kinds of changes should never be possible via GET requests, so that people can't link each other to unwittingly performing changes on the site.
In your view, check that request.user is the same as the author of that particular model instance. You could also check that the HTTP_REFERRER is not set to another site if you were really worried.
Your security issue here is Cross Site Request Forgery. Django provides CsrfMiddleware which will actually add security to your forms to prevent this kind of attack. But it only works as long as you're not allowing permanent changes to take place via GET requests. | 1 | 0 | 0 | I would like to give users access to delete a model instance that they added to the db. In the django docs it says allowing someone to delete from the template is not a good practice. Is there a secure way to let a user click a "delete this" link from the template and remove that model instance? How should I go about doing that? | What is the best secure way to allow a user to delete a model instance that they added to the db? | 0 | 0 | 0 | 216 |
771,341 | 2009-04-21T06:49:00.000 | 1 | 1 | 0 | 0 | php,python,lighttpd,configure | 771,528 | 2 | false | 0 | 0 | You can also enable Lighty to use .pl, .py and .php as 'cgi' by enabling mod_cgi and setting it up. The default configs are on the Lighty website. However, this will have the benefits and problems of running an independent cgi process. If you are only experiencing light traffic, performance shouldn't be an issue. | 1 | 3 | 0 | I've set up a few web servers in my day, but I'm not sure how they work internally. I'm setting up a new environment for myself and I'm interested in configuring my lighttpd server to support both PHP and Python. Is this possible? | Python + PHP + Lighttpd? | 0.099668 | 0 | 0 | 3,056 |
771,399 | 2009-04-21T07:11:00.000 | 2 | 0 | 0 | 0 | python,tcp,monitoring,port | 771,422 | 5 | true | 0 | 0 | I'd recommend not leaving your (single) test socket connected - make a new connection each time you need to poll. Every load balancer / server availability system I've ever seen uses this method instead of a persistent connection.
If the remote server hasn't responded within a reasonable amount of time (e.g. 10s) mark it as "down". Use timers and signals rather than function response codes to handle that timeout. | 4 | 3 | 0 | For fun, I've been toying around with writing a load balancer in python and have been trying to figure the best (correct?) way to test if a port is available and the remote host is still there.
I'm finding that, once connected, it becomes difficult to tell when the remote host goes down. I've turned keep alive on, but can't get it to recognize a downed connection sooner than a minute (I realize polling more often than a minute might be overkill, but lets say I wanted to), even after setting the various TCP_KEEPALIVE options to their lowest.
When I use nonblocking sockets, I've noticed that a recv() will return an error ("resource temporarily unavailable") when it reads from a live socket, but returns "" when reading from a dead one (send and recv of 0 bytes, which might be the cause?). That seems like an odd way to test for it connected, though, and makes it impossible to tell if the connected died but after sending some data.
Aside from connecting/disconnecting for every check, is there something I can do? Can I manually send a tcp keepalive, or can I establish a lower level connection that will let me test the connectivity without sending real data the remote server would potentially process? | Monitoring a tcp port | 1.2 | 0 | 1 | 3,463 |
771,399 | 2009-04-21T07:11:00.000 | 0 | 0 | 0 | 0 | python,tcp,monitoring,port | 771,438 | 5 | false | 0 | 0 | It is theoretically possible to spam a keepalive packet. But to set it to very low intervals, you may need to dig into raw sockets. Also, your host may ignore it if its coming in too fast.
The best way to check if a host is alive in a TCP connection is to send data, and wait for an ACK packet. If the ACK packet arrives, the SEND function will return non-zero. | 4 | 3 | 0 | For fun, I've been toying around with writing a load balancer in python and have been trying to figure the best (correct?) way to test if a port is available and the remote host is still there.
I'm finding that, once connected, it becomes difficult to tell when the remote host goes down. I've turned keep alive on, but can't get it to recognize a downed connection sooner than a minute (I realize polling more often than a minute might be overkill, but lets say I wanted to), even after setting the various TCP_KEEPALIVE options to their lowest.
When I use nonblocking sockets, I've noticed that a recv() will return an error ("resource temporarily unavailable") when it reads from a live socket, but returns "" when reading from a dead one (send and recv of 0 bytes, which might be the cause?). That seems like an odd way to test for it connected, though, and makes it impossible to tell if the connected died but after sending some data.
Aside from connecting/disconnecting for every check, is there something I can do? Can I manually send a tcp keepalive, or can I establish a lower level connection that will let me test the connectivity without sending real data the remote server would potentially process? | Monitoring a tcp port | 0 | 0 | 1 | 3,463 |
771,399 | 2009-04-21T07:11:00.000 | 1 | 0 | 0 | 0 | python,tcp,monitoring,port | 773,207 | 5 | false | 0 | 0 | "it becomes difficult to tell when the remote host goes down"
Correct. This is a feature of TCP. The whole point of TCP is to have an enduring connection between ports. Theoretically an application can drop and reconnect to the port through TCP (the socket libraries don't provide a lot of support for this, but it's part of the TCP protocol). | 4 | 3 | 0 | For fun, I've been toying around with writing a load balancer in python and have been trying to figure the best (correct?) way to test if a port is available and the remote host is still there.
I'm finding that, once connected, it becomes difficult to tell when the remote host goes down. I've turned keep alive on, but can't get it to recognize a downed connection sooner than a minute (I realize polling more often than a minute might be overkill, but lets say I wanted to), even after setting the various TCP_KEEPALIVE options to their lowest.
When I use nonblocking sockets, I've noticed that a recv() will return an error ("resource temporarily unavailable") when it reads from a live socket, but returns "" when reading from a dead one (send and recv of 0 bytes, which might be the cause?). That seems like an odd way to test for it connected, though, and makes it impossible to tell if the connected died but after sending some data.
Aside from connecting/disconnecting for every check, is there something I can do? Can I manually send a tcp keepalive, or can I establish a lower level connection that will let me test the connectivity without sending real data the remote server would potentially process? | Monitoring a tcp port | 0.039979 | 0 | 1 | 3,463 |
771,399 | 2009-04-21T07:11:00.000 | 0 | 0 | 0 | 0 | python,tcp,monitoring,port | 771,415 | 5 | false | 0 | 0 | ping was invented for that purpose
also you might be able to send malformed TCP packets to your destination. For example, in the TCP headers there is a flag for acknowleging end of transmission, its the FIN message. If you send a message with ACK and FIN the remote host should complain with a return packet and you'll be able to evaluate round trip time. | 4 | 3 | 0 | For fun, I've been toying around with writing a load balancer in python and have been trying to figure the best (correct?) way to test if a port is available and the remote host is still there.
I'm finding that, once connected, it becomes difficult to tell when the remote host goes down. I've turned keep alive on, but can't get it to recognize a downed connection sooner than a minute (I realize polling more often than a minute might be overkill, but lets say I wanted to), even after setting the various TCP_KEEPALIVE options to their lowest.
When I use nonblocking sockets, I've noticed that a recv() will return an error ("resource temporarily unavailable") when it reads from a live socket, but returns "" when reading from a dead one (send and recv of 0 bytes, which might be the cause?). That seems like an odd way to test for it connected, though, and makes it impossible to tell if the connected died but after sending some data.
Aside from connecting/disconnecting for every check, is there something I can do? Can I manually send a tcp keepalive, or can I establish a lower level connection that will let me test the connectivity without sending real data the remote server would potentially process? | Monitoring a tcp port | 0 | 0 | 1 | 3,463 |
771,738 | 2009-04-21T09:09:00.000 | 0 | 0 | 0 | 1 | python,flex3,air | 3,895,749 | 4 | false | 0 | 0 | Air 2.0 has a native process API. | 3 | 1 | 0 | How can we invoke a python script using AIR 1.5? | Call python script from AIR application? | 0 | 0 | 0 | 1,223 |
771,738 | 2009-04-21T09:09:00.000 | -1 | 0 | 0 | 1 | python,flex3,air | 771,836 | 4 | false | 0 | 0 | Hypothetically, Adobe Alchemy technology may allow you to port Python interpreter to Flash.
Though I seriously doubt that's the approach you want to use. Depending on task there should be easier solutions. | 3 | 1 | 0 | How can we invoke a python script using AIR 1.5? | Call python script from AIR application? | -0.049958 | 0 | 0 | 1,223 |
771,738 | 2009-04-21T09:09:00.000 | 1 | 0 | 0 | 1 | python,flex3,air | 771,745 | 4 | true | 0 | 0 | You cannot directly invoke system commands or run an executable (the python interpreter) from within an AIR application. If it's possible to share what exactly you want to do, maybe we can suggest alternatives.
If it's really really (that's two reallys) important to run an executable from AIR lookup the CommandProxy demo. | 3 | 1 | 0 | How can we invoke a python script using AIR 1.5? | Call python script from AIR application? | 1.2 | 0 | 0 | 1,223 |
771,816 | 2009-04-21T09:35:00.000 | 1 | 0 | 1 | 1 | python,subprocess | 772,743 | 4 | true | 0 | 0 | When you execute an external process, the command you want may look something like "foo arg1 arg2 arg3". If "foo" is an executable, that is what gets executed and given the arguments.
However, often it is the case that "foo" is actually a script of some sort, or maybe a command that is built-in to the shell and not an actual executable file on disk. In this case the system can't execute "foo" directly because, strictly speaking, these sorts of things aren't executable. They need some sort of "shell" to execute them. On *nix systems this shell is typically (but not necessarily) /bin/sh. On windows it will typically be cmd.exe (or whatever is stored in the COMSPEC environment variable).
This parameter lets you define what shell you wish to use to execute your command, for the relatively rare case when you don't want the default. | 1 | 1 | 0 | The docs for the subprocess module state that 'If shell is True, the specified command will be executed through the shell'. What does this mean in practice, on a Windows OS? | What does the 'shell' argument in subprocess mean on Windows? | 1.2 | 0 | 0 | 1,280 |
772,240 | 2009-04-21T12:05:00.000 | 2 | 0 | 0 | 0 | python,django | 850,508 | 6 | false | 1 | 0 | Django paypal is very cool. I've used in on couple of my projects. It is relatively easy to integrate with an existing website.
Satchmo is good, if you want a full internet store, but if you want to sell just couple items from your website, which is devoted to something else, you will find Satchmo to be very heavy (a lot of dependencies to install, really complicates your admin). | 1 | 24 | 0 | Can anyone suggest any good payment processing libraries for python/django? | Django payment processing | 0.066568 | 0 | 0 | 8,276 |
772,814 | 2009-04-21T14:20:00.000 | 3 | 1 | 1 | 0 | python,zip | 772,842 | 1 | true | 0 | 0 | I've looked for this in the past and been unsuccessful. (I'd love to see a solution get posted!)
One option is a commercial package from chilkatsoft that will do this, but at $150. Makes sense if you are doing a commercial app, but tough to swallow otherwise.
I wound up calling out to the system for my solution, a while ago. Unfortunately, this locks it to a platform. | 1 | 3 | 0 | Since python2.6, it's now easier to extract data from a password protected zip. But how to create a password protected zipfile in pure python ? | How to create a password protected zipfile with python? | 1.2 | 0 | 0 | 1,457 |
772,922 | 2009-04-21T14:43:00.000 | 33 | 0 | 1 | 0 | python,dictionary,word-list | 772,936 | 7 | false | 0 | 0 | Most unix (which includes osx) have a file /usr/share/dict/words. | 1 | 43 | 0 | A friend of mine was talking about a word game she liked to play where you try to convert one word to another (they have the same number of letters) by switching one letter at a time, where each iteration produces a real word.
Example:
MOON --> WOLF
GOON
GOOF
GOLF
WOLF
I figured it'd be a fun little project to write a program to generate solutions, and taking it further, given 2 words, determine if a solution exists and the number of iterations in optimal solution.
Problem is I'm having trouble finding free word lists that I can easily access programmatically. I'm also thinking about using this as an excuse to learn Python, so it'd be great if anyone knows of free word lists and pointers on how to parse and access it from Python. The algorithm for figuring out how to find an optimal path I'll work on my own. | Free word list for use programmatically? | 1 | 0 | 0 | 67,206 |
774,784 | 2009-04-21T21:49:00.000 | 20 | 0 | 1 | 0 | python,operator-overloading | 774,792 | 5 | true | 0 | 0 | There is no ++ operator in Python (nor '--'). Incrementing is usually done with the += operator instead. | 2 | 2 | 0 | Is it possible to overload ++ operators in Python? | Is it possible to overload ++ operators in Python? | 1.2 | 0 | 0 | 3,719 |
774,784 | 2009-04-21T21:49:00.000 | 5 | 0 | 1 | 0 | python,operator-overloading | 774,794 | 5 | false | 0 | 0 | Well, the ++ operator doesn't exist in Python, so you really can't overload it.
What happens when you do something like:
1 ++ 2
is actually
1 + (+2) | 2 | 2 | 0 | Is it possible to overload ++ operators in Python? | Is it possible to overload ++ operators in Python? | 0.197375 | 0 | 0 | 3,719 |
775,161 | 2009-04-21T23:48:00.000 | 4 | 0 | 0 | 0 | python,mysql,performance,solr | 775,354 | 7 | false | 0 | 0 | You say you're using SOLR, don't care about storage, and want the lookups to be fast. Then instead of storing open/close tuples, index an entry for every open block of time at the level of granularity you need (15 mins). For the encoding itself, you could use just cumulative hours:minutes.
For example, a store open from 4-5 pm on Monday, would have indexed values added for [40:00, 40:15, 40:30, 40:45]. A query at 4:24 pm on Monday would be normalized to 40:15, and therefore match that store document.
This may seem inefficient at first glance, but it's a relatively small constant penalty for indexing speed and space. And makes the searches as fast as possible. | 5 | 6 | 0 | Given a time (eg. currently 4:24pm on Tuesday), I'd like to be able to select all businesses that are currently open out of a set of businesses.
I have the open and close times for every business for every day of the week
Let's assume a business can open/close only on 00, 15, 30, 45 minute marks of each hour
I'm assuming the same schedule each week.
I am most interested in being able to quickly look up a set of businesses that is open at a certain time, not the space requirements of the data.
Mind you, some my open at 11pm one day and close 1am the next day.
Holidays don't matter - I will handle these separately
What's the most efficient way to store these open/close times such that with a single time/day-of-week tuple I can speedily figure out which businesses are open?
I am using Python, SOLR and mysql. I'd like to be able to do the querying in SOLR. But frankly, I'm open to any suggestions and alternatives. | Efficiently determining if a business is open or not based on store hours | 0.113791 | 1 | 0 | 1,489 |
775,161 | 2009-04-21T23:48:00.000 | 8 | 0 | 0 | 0 | python,mysql,performance,solr | 775,247 | 7 | true | 0 | 0 | If you are willing to just look at single week at a time, you can canonicalize all opening/closing times to be set numbers of minutes since the start of the week, say Sunday 0 hrs. For each store, you create a number of tuples of the form [startTime, endTime, storeId]. (For hours that spanned Sunday midnight, you'd have to create two tuples, one going to the end of the week, one starting at the beginning of the week). This set of tuples would be indexed (say, with a tree you would pre-process) on both startTime and endTime. The tuples shouldn't be that large: there are only ~10k minutes in a week, which can fit in 2 bytes. This structure would be graceful inside a MySQL table with appropriate indexes, and would be very resilient to constant insertions & deletions of records as information changed. Your query would simply be "select storeId where startTime <= time and endtime >= time", where time was the canonicalized minutes since midnight on sunday.
If information doesn't change very often, and you want to have lookups be very fast, you could solve every possible query up front and cache the results. For instance, there are only 672 quarter-hour periods in a week. With a list of businesses, each of which had a list of opening & closing times like Brandon Rhodes's solution, you could simply, iterate through every 15-minute period in a week, figure out who's open, then store the answer in a lookup table or in-memory list. | 5 | 6 | 0 | Given a time (eg. currently 4:24pm on Tuesday), I'd like to be able to select all businesses that are currently open out of a set of businesses.
I have the open and close times for every business for every day of the week
Let's assume a business can open/close only on 00, 15, 30, 45 minute marks of each hour
I'm assuming the same schedule each week.
I am most interested in being able to quickly look up a set of businesses that is open at a certain time, not the space requirements of the data.
Mind you, some my open at 11pm one day and close 1am the next day.
Holidays don't matter - I will handle these separately
What's the most efficient way to store these open/close times such that with a single time/day-of-week tuple I can speedily figure out which businesses are open?
I am using Python, SOLR and mysql. I'd like to be able to do the querying in SOLR. But frankly, I'm open to any suggestions and alternatives. | Efficiently determining if a business is open or not based on store hours | 1.2 | 1 | 0 | 1,489 |
775,161 | 2009-04-21T23:48:00.000 | 3 | 0 | 0 | 0 | python,mysql,performance,solr | 775,175 | 7 | false | 0 | 0 | Sorry I don't have an easy answer, but I can tell you that as the manager of a development team at a company in the late 90's we were tasked with solving this very problem and it was HARD.
It's not the weekly hours that's tough, that can be done with a relatively small bitmask (168 bits = 1 per hour of the week), the trick is the businesses which are closed every alternating Tuesday.
Starting with a bitmask then moving on to an exceptions field is the best solution I've ever seen. | 5 | 6 | 0 | Given a time (eg. currently 4:24pm on Tuesday), I'd like to be able to select all businesses that are currently open out of a set of businesses.
I have the open and close times for every business for every day of the week
Let's assume a business can open/close only on 00, 15, 30, 45 minute marks of each hour
I'm assuming the same schedule each week.
I am most interested in being able to quickly look up a set of businesses that is open at a certain time, not the space requirements of the data.
Mind you, some my open at 11pm one day and close 1am the next day.
Holidays don't matter - I will handle these separately
What's the most efficient way to store these open/close times such that with a single time/day-of-week tuple I can speedily figure out which businesses are open?
I am using Python, SOLR and mysql. I'd like to be able to do the querying in SOLR. But frankly, I'm open to any suggestions and alternatives. | Efficiently determining if a business is open or not based on store hours | 0.085505 | 1 | 0 | 1,489 |
775,161 | 2009-04-21T23:48:00.000 | 0 | 0 | 0 | 0 | python,mysql,performance,solr | 775,459 | 7 | false | 0 | 0 | Have you looked at how many unique open/close time combinations there are? If there are not that many, make a reference table of the unique combinations and store the index of the appropriate entry against each business. Then you only have to search the reference table and then find the business with those indices. | 5 | 6 | 0 | Given a time (eg. currently 4:24pm on Tuesday), I'd like to be able to select all businesses that are currently open out of a set of businesses.
I have the open and close times for every business for every day of the week
Let's assume a business can open/close only on 00, 15, 30, 45 minute marks of each hour
I'm assuming the same schedule each week.
I am most interested in being able to quickly look up a set of businesses that is open at a certain time, not the space requirements of the data.
Mind you, some my open at 11pm one day and close 1am the next day.
Holidays don't matter - I will handle these separately
What's the most efficient way to store these open/close times such that with a single time/day-of-week tuple I can speedily figure out which businesses are open?
I am using Python, SOLR and mysql. I'd like to be able to do the querying in SOLR. But frankly, I'm open to any suggestions and alternatives. | Efficiently determining if a business is open or not based on store hours | 0 | 1 | 0 | 1,489 |
775,161 | 2009-04-21T23:48:00.000 | 1 | 0 | 0 | 0 | python,mysql,performance,solr | 777,443 | 7 | false | 0 | 0 | In your Solr index, instead of indexing each business as one document with hours, index every "retail session" for every business during the course of a week.
For example if Joe's coffee is open Mon-Sat 6am-9pm and closed on Sunday, you would index six distinct documents, each with two indexed fields, "open" and "close". If your units are 15 minute intervals, then the values can range from 0 to 7*24*4. Assuming you have a unique ID for each business, store this in each document so you can map the sessions to businesses.
Then you can simply do a range search in Solr:
open:[* TO N] AND close:[N+1 TO *]
where N is computed to the Nth 15 minute interval that the current time falls into. For examples if it's 10:10AM on Wednesday, your query would be:
open:[* TO 112] AND close:[113 TO *]
aka "find a session that starts at or before 10:00am Wed and ends at or after 10:15am Wed"
If you want to include other criteria in your search, such as location or products, you will need to index this with each session document as well. This is a bit redundant, but if your index is not huge, it shouldn't be a problem. | 5 | 6 | 0 | Given a time (eg. currently 4:24pm on Tuesday), I'd like to be able to select all businesses that are currently open out of a set of businesses.
I have the open and close times for every business for every day of the week
Let's assume a business can open/close only on 00, 15, 30, 45 minute marks of each hour
I'm assuming the same schedule each week.
I am most interested in being able to quickly look up a set of businesses that is open at a certain time, not the space requirements of the data.
Mind you, some my open at 11pm one day and close 1am the next day.
Holidays don't matter - I will handle these separately
What's the most efficient way to store these open/close times such that with a single time/day-of-week tuple I can speedily figure out which businesses are open?
I am using Python, SOLR and mysql. I'd like to be able to do the querying in SOLR. But frankly, I'm open to any suggestions and alternatives. | Efficiently determining if a business is open or not based on store hours | 0.028564 | 1 | 0 | 1,489 |
775,351 | 2009-04-22T01:09:00.000 | 3 | 0 | 1 | 1 | python,windows | 777,067 | 5 | false | 0 | 0 | Please note that checking for existance and then opening is always open to race-conditions. The file can disappear between your program's check and its next access of the file, since other programs continue to run on the machine.
Thus there might still be an exception being thrown, even though your code is "certain" that the file exists. This is, after all, why they're called exceptions. | 2 | 16 | 0 | I commonly use os.path.exists() to check if a file is there before doing anything with it.
I've run across a situation where I'm calling a executable that's in the configured env path, so it can be called without specifying the abspath.
Is there something that can be done to check if the file exists before calling it?
(I may fall back on try/except, but first I'm looking for a replacement for os.path.exists())
btw - I'm doing this on windows. | os.path.exists() for files in your Path? | 0.119427 | 0 | 0 | 87,347 |
775,351 | 2009-04-22T01:09:00.000 | 2 | 0 | 1 | 1 | python,windows | 777,961 | 5 | false | 0 | 0 | You generally shouldn't should os.path.exists to try to figure out if something is going to succeed. You should just try it and if you want you can handle the exception if it fails. | 2 | 16 | 0 | I commonly use os.path.exists() to check if a file is there before doing anything with it.
I've run across a situation where I'm calling a executable that's in the configured env path, so it can be called without specifying the abspath.
Is there something that can be done to check if the file exists before calling it?
(I may fall back on try/except, but first I'm looking for a replacement for os.path.exists())
btw - I'm doing this on windows. | os.path.exists() for files in your Path? | 0.07983 | 0 | 0 | 87,347 |
775,880 | 2009-04-22T05:55:00.000 | 1 | 0 | 1 | 1 | python,egg | 775,908 | 2 | false | 0 | 0 | Adding the egg to PYTHONPATH or to sys.path will allow you to access the modules and packages within. | 1 | 1 | 0 | Is there any way to call an installed python egg from python code? I need to cal a sphinx documentation
generator from within a python code, and currently i'm doing it like this:
os.system( "sphinx-build.exe -b html c:\\src c:\\dst" )
This works, but requires some additional configuration: 'scripts' folder
inside a python installation folder need to be added to a system PATH
( i'm on Windows ). Is it any better, native way to call an installed python
egg? | access eggs in python? | 0.099668 | 0 | 0 | 412 |
777,090 | 2009-04-22T12:56:00.000 | 3 | 1 | 0 | 0 | python,xml,json | 777,119 | 3 | true | 0 | 0 | If a flat file is fast enough, then go with that, since it's very simple and accessible. Storing as XML and JSON but still using a flat file probably is very comparable in performance.
You might want to consider (ignore this if you just left it out of your question) sanitizing/filtering the text, so that users can't break your HTML by e.g. entering "</p>" in the comment text. | 1 | 1 | 0 | Hi I have a small comment shoutbox type cgi process running on a server and currently when someone leaves a comment I simply format that comment into html i.e
<p class="title">$title</p>
<p class="comment">$comment</p>
and store in a flat file.
Would it be faster and acceptably low in LOC to reimplement the storage in xml or json, in a simple spec of my own or stick with the simple html route?.
I don't want to use relational database for this. | fastest way to store comment data python | 1.2 | 0 | 1 | 331 |
777,525 | 2009-04-22T14:36:00.000 | 2 | 1 | 1 | 0 | python,byte | 777,746 | 7 | false | 0 | 0 | I take it you mean you only want to use as many bytes as you need to represent the number? e.g. if the number is:
255 or less you'd use only 1 byte
65535 or less 2 bytes
16777215 or less 3 bytes
etc etc
On the Psion PDA they'd usually have some of packing scheme in which you read the first byte, detect if it has the highest bit set and then read another byte if it has. That way you'd just keep reading bytes until you read the "full" number. That system works quite well if most of the numbers you are dealing with are fairly small, as you'll normally only use one or two bytes per number.
The alternative is to have one (or more) bytes representing the number of total bytes used, but at that point it's basically a string in Python anyway. i.e. it's a string of base-256 digits. | 1 | 14 | 0 | The struct.pack() function allows converting integers of up to 64 bit to byte strings. What's the most efficient way to pack an even larger integer? I'd rather not add a dependency on non-standard modules like PyCrypto (which provides num_to_bytes()). | Efficient arbitrary-sized integer packing in Python | 0.057081 | 0 | 0 | 4,223 |
777,778 | 2009-04-22T15:18:00.000 | 2 | 0 | 0 | 0 | python,django,oracle,autofield | 778,346 | 1 | true | 1 | 0 | The DB is responsible for managing the value of the ID. If you want to use AutoField, you have to change the column in the DB to use that. Django is not responsible for managing the generated ID | 1 | 1 | 0 | I have a legacy database with an integer set as a primary key. It was initially managed manually, but since we are wanting to move to django, the admin tool seemed to be the right place to start. I created the model and am trying to set the primary key to be an autofield. It doesn't seem to be remembering the old id in updates, and it doesn't create new id's on insert. What am I doing wrong? | How do I set up a model to use an AutoField with a legacy database in Python? | 1.2 | 1 | 0 | 454 |
777,924 | 2009-04-22T15:46:00.000 | 0 | 1 | 0 | 0 | python | 777,952 | 5 | false | 0 | 0 | Oh, golly.
Look, this is gonna be real hard to answer because, read as you wrote it, you're missing a lot of steps. Like, you need a web server, a design, some HTML, and so on.
Are you building from the ground up? Asking about Python makes me suspect you may be using something like Zope. | 1 | 0 | 0 | Other than basic python syntax, what other key areas should I learn to get a website live?
Is there a web.config in the python world?
Which libraries handle things like authentication? or is that all done manually via session cookies and database tables?
Are there any web specific libraries?
Edit: sorry!
I am well versed in asp.net, I want to branch out and learn Python, hence this question (sorry, terrible start to this question I know). | Other than basic python syntax, what other key areas should I learn to get a website live? | 0 | 0 | 1 | 177 |
778,093 | 2009-04-22T16:23:00.000 | 0 | 0 | 0 | 0 | python,excel,search,pyexcelerator,xlrd | 779,599 | 4 | false | 0 | 0 | With pyExcelerator you can do a simple optimization by finding the maximum row and column indices first (and storing them), so that you iterate over (row, i) for i in range(maxcol+1) instead of iterating over all the dictionary keys. That may be the best you get, unless you want to go through and build up a dictionary mapping value to set of keys.
Incidentally, if you're using pyExcelerator to write spreadsheets, be aware that it has some bugs. I've encountered one involving writing integers between 230 and 232 (or thereabouts). The original author is apparently hard to contact these days, so xlwt is a fork that fixes the (known) bugs. For writing spreadsheets, it's a drop-in replacement for pyExcelerator; you could do import xlwt as pyExcelerator and change nothing else. It doesn't read spreadsheets, though. | 3 | 2 | 0 | Python communicating with EXCEL... i need to find a way so that I can find/search a row for given column datas. Now, i m scanning entire rows one by one... It would be useful, If there is some functions like FIND/SEARCH/REPLACE .... I dont see these features in pyExcelerator or xlrd modules.. I dont want to use win32com modules! it makes my tool windows based!
FIND/SEARCH Excel rows through Python.... Any idea, anybody? | pyExcelerator or xlrd - How to FIND/SEARCH a row for the given few column data? | 0 | 1 | 0 | 7,840 |
778,093 | 2009-04-22T16:23:00.000 | 2 | 0 | 0 | 0 | python,excel,search,pyexcelerator,xlrd | 779,030 | 4 | false | 0 | 0 | You can't. Those tools don't offer search capabilities. You must iterate over the data in a loop and search yourself. Sorry. | 3 | 2 | 0 | Python communicating with EXCEL... i need to find a way so that I can find/search a row for given column datas. Now, i m scanning entire rows one by one... It would be useful, If there is some functions like FIND/SEARCH/REPLACE .... I dont see these features in pyExcelerator or xlrd modules.. I dont want to use win32com modules! it makes my tool windows based!
FIND/SEARCH Excel rows through Python.... Any idea, anybody? | pyExcelerator or xlrd - How to FIND/SEARCH a row for the given few column data? | 0.099668 | 1 | 0 | 7,840 |
778,093 | 2009-04-22T16:23:00.000 | 2 | 0 | 0 | 0 | python,excel,search,pyexcelerator,xlrd | 778,282 | 4 | false | 0 | 0 | "Now, i m scanning entire rows one by one"
What's wrong with that? "search" -- in a spreadsheet context -- is really complicated. Search values? Search formulas? Search down rows then across columns? Search specific columns only? Search specific rows only?
A spreadsheet isn't simple text -- simple text processing design patterns don't apply.
Spreadsheet search is hard and you're doing it correctly. There's nothing better because it's hard. | 3 | 2 | 0 | Python communicating with EXCEL... i need to find a way so that I can find/search a row for given column datas. Now, i m scanning entire rows one by one... It would be useful, If there is some functions like FIND/SEARCH/REPLACE .... I dont see these features in pyExcelerator or xlrd modules.. I dont want to use win32com modules! it makes my tool windows based!
FIND/SEARCH Excel rows through Python.... Any idea, anybody? | pyExcelerator or xlrd - How to FIND/SEARCH a row for the given few column data? | 0.099668 | 1 | 0 | 7,840 |
779,675 | 2009-04-22T23:31:00.000 | 0 | 0 | 1 | 0 | python,debugging | 779,684 | 9 | false | 0 | 0 | Your question is not very clear, but I assume that the python interpreter exits (and therefore the calling console window closes) when an exception happens.
You need to modify your python application to catch the exception and print it without exiting the interpreter. One way to do that is to print "press ENTER to exit" and then read some input from the console window, effectively waiting for the user to press Enter. | 3 | 22 | 0 | In python when running scripts is there a way to stop the console window from closing after spitting out the traceback? | Stop python from closing on error | 0 | 0 | 0 | 45,950 |
779,675 | 2009-04-22T23:31:00.000 | 3 | 0 | 1 | 0 | python,debugging | 14,227,240 | 9 | false | 0 | 0 | In windows instead of double clicking the py file you can drag it into an already open CMD window, and then hit enter. It stays open after an exception.
Dan | 3 | 22 | 0 | In python when running scripts is there a way to stop the console window from closing after spitting out the traceback? | Stop python from closing on error | 0.066568 | 0 | 0 | 45,950 |
779,675 | 2009-04-22T23:31:00.000 | 8 | 0 | 1 | 0 | python,debugging | 780,509 | 9 | false | 0 | 0 | On UNIX systems (Windows has already been covered above...) you can change the interpreter argument to include the -i flag:
#!/usr/bin/python -i
From the man page:
-i
When a script is passed as first argument or the -c option is used, enter interactive mode after executing the script or the command. It does not read the $PYTHONSTARTUP file. This can be useful to inspect global variables or a stack trace when a script raises an exception. | 3 | 22 | 0 | In python when running scripts is there a way to stop the console window from closing after spitting out the traceback? | Stop python from closing on error | 1 | 0 | 0 | 45,950 |
779,989 | 2009-04-23T01:41:00.000 | 1 | 0 | 1 | 0 | python,logging,methodology | 780,068 | 7 | false | 0 | 0 | A good idea is to look at log analysis software. Unless you plan to write your own, you will probably want to exploit an existing log analysis package such as Analog. If that is the case, you will probably want to generate a log output that is similar enough to the formats that it accepts. It will allow you to create nice charts and graphs with minimal effort! | 3 | 11 | 0 | My question is simple: what to write into a log.
Are there any conventions?
What do I have to put in?
Since my app has to be released, I'd like to have friendly logs, which could be read by most people without asking what it is.
I already have some ideas, like a timestamp, a unique identifier for each function/method, etc..
I'd like to have several log levels, like tracing/debugging, informations, errors/warnings.
Do you use some pre-formatted log resources?
Thank you | What to write into log file? | 0.028564 | 0 | 0 | 3,663 |
779,989 | 2009-04-23T01:41:00.000 | 9 | 0 | 1 | 0 | python,logging,methodology | 779,995 | 7 | true | 0 | 0 | Here are some suggestions for content:
timestamp
message
log message type (such as error, warning, trace, debug)
thread id ( so you can make sense of the log file from a multi threaded application)
Best practices for implementation:
Put a mutex around the write method so that you can be sure that each write is thread safe and will make sense.
Send 1 message at at a time to the log file, and specify the type of log message each time. Then you can set what type of logging you want to take on program startup.
Use no buffering on the file, or flush often in case there is a program crash.
Edit: I just noticed the question was tagged with Python, so please see S. Lott's answer before mine. It may be enough for your needs. | 3 | 11 | 0 | My question is simple: what to write into a log.
Are there any conventions?
What do I have to put in?
Since my app has to be released, I'd like to have friendly logs, which could be read by most people without asking what it is.
I already have some ideas, like a timestamp, a unique identifier for each function/method, etc..
I'd like to have several log levels, like tracing/debugging, informations, errors/warnings.
Do you use some pre-formatted log resources?
Thank you | What to write into log file? | 1.2 | 0 | 0 | 3,663 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.