If you are worried about performance you should take a look at the module "timeit".
Between the 2 previous codes (for & while), it's faster the while code.... but just a little, and makes the code ugliest.
BTW, never bench functions with "print" statements, because it's too slow and make no sense.
User Profile
Collapse
-
You can't... :(
You should use an external zip program with command line support, and call it with "subprocess " .Leave a comment:
-
At first: Post code between [code ] [ /code] tags ...
Second: the "f" file object has like a "pointer" pointing where it's reading... after a "for" loop, that pointer keeps on EOF until you reload the file (re create the object) or until you do f.seek(0).
That's why function 1 works and function 2 doesn't...Leave a comment:
-
I think you post in the wrong section... that isn't Python, right?Leave a comment:
-
Same Object !
This should be so easy, but i'm stuck... i want to have two local copies of an incoming object (in this case, a ConfigParser), to modify one of them and later compare them. The problem is that this code give me two names to the SAME object!!!
[code=Python]class updater():
def __init__(self, config):
self.__config = config
self.__oldconf = config [/code]
How can i have an independent... -
Where is the inconsistancy?? ?? It's pretty clear, the only thing that you have to do is read the docs...
Code:int( [x[, radix]]) Convert a string or number to a plain integer. If the argument is a string, it must contain a possibly signed decimal number representable as a Python integer, possibly embedded in whitespace. The radix parameter gives the base for the conversion and may be any integer in the range [2, 36], or
Leave a comment:
-
This sentence should achieve that:
[CODE=Python]sys.stderr = sys.stdout[/CODE]
Code:stdin stdout stderr File objects corresponding to the interpreter's standard input, output and error streams. stdin is used for all interpreter input except for scripts but including calls to input() and raw_input(). stdout is used for the output of print and expression statements and for the prompts of input() and raw_input().
Leave a comment:
-
I can't figure out what do you really want, but take a look at : os.walk()Leave a comment:
-
-
What about this:
Code:import os def searchForDir( dir_looking_for, path_to_search_for, debug = False): results=[] for root, dirs, files in os.walk( path_to_search_for ): if dir_looking_for in dirs: results.append(root) if debug: if results: print "There is %i results for your query, and they are: " % (len(results),)
Leave a comment:
-
You could capture the output of the system-dependent command to get the directory size... i don't know which one is more efficient.Leave a comment:
-
Take a look at "cgi-bin" alias and directory at "httpd.conf " .
The default cgi-bin directory is in the Apache directory, probably not the one that you are using..Leave a comment:
-
Send file to server unnatended
Hi! I'm new here and also new in Python, and i have a simple question:
I have:
-a python program running on a Linux machine
-a Windows XP machine with a WAMP Server, and python for Windows installed too.
I wanna:
- send a file from the client to the server, in the easiest and most effective way possible, without user interference.
I reed a lot about it, but i cannot made it to work.... -
-
Please post the code with [code ] and [/ code] to keep indentation !Leave a comment:
-
Yes... that's it. OMG, I feel so silly right now, what a dumb mistake !!
Thanks a lot!Leave a comment:
-
Here is the entire .py file, isn't so long so i decided to post it complete. Hope you can help me, thanks in advance :)
(also hope that the "spanish locale" wasn't a problem to debug :) )
Code:# -*- coding: cp1252 -*- import sys, urllib, urllib2, commands, os, datetime, ConfigParser, signal import string, time, logging, logging.handlers, subprocess import httplib, inspect def
Leave a comment:
-
Issue with return statement inside except of for
I have this code inside a function:
Code:try: for linea in subprocess.Popen(comando, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True).stdout: req = urllib2.Request(URL, "&mac_addr=" + mac_addr + " &sampled_time=" + sampled_time + " &line_data=" + linea) ret = urllib2.urlopen(req).read() except (urllib2.URLError, httplib.HTTPException):
No activity results to display
Show More
Leave a comment: