Re: HTTP Authentication using urllib2

2009-04-24 Thread Wojtek Walczak
shoot yourself in the foot and check what the exceptions are, i.e.: except: import traceback print traceback.format_exc() Second, better use mechanize: http://wwwsearch.sourceforge.net/mechanize/ HTH, -- Regards, Wojtek Walczak, http://tosh.pl/gminick/ -- http://mail.

Re: python alternatives to C structs??

2009-04-18 Thread Wojtek Walczak
ary/struct.html http://www.doughellmann.com/PyMOTW/struct/index.html http://code.activestate.com/recipes/498149/ HTH, -- Regards, Wojtek Walczak, http://tosh.pl/gminick/ -- http://mail.python.org/mailman/listinfo/python-list

Re: I'm sort of mystified by the print hex to char conversion

2009-04-18 Thread Wojtek Walczak
slash is left in the string. (This behavior is useful when debugging: if an escape sequence is mistyped, the resulting output is more easily recognized as broken.) So, as long as the escape sequence is recognized it is changed accordingly. -- Regards, Wojtek Walczak, http://tosh.pl/gminick/ -- http://mail.python.org/mailman/listinfo/python-list

Re: Equivalent to C bitmasks and enumerations

2009-04-15 Thread Wojtek Walczak
7;RED') c.set_color('YELLOW') print c.has_color('RED') print c.has_color('BLUE') print c.status_as_string(5) HTH, -- Regards, Wojtek Walczak, http://tosh.pl/gminick/ -- http://mail.python.org/mailman/listinfo/python-list

Re: HTTPError... read the response body?

2009-03-02 Thread Wojtek Walczak
[1] a valid URL? And are you sure that you want to send something to the web serwer? By specifying the second argument (args[3]) you're asking python to send HTTP "POST" request, not "GET". -- Regards, Wojtek Walczak, http://tosh.pl/gminick/ -- http://mail.python.org/mailman/listinfo/python-list

Re: urlparse import Faillure

2008-10-10 Thread Wojtek Walczak
ting rid of this comment? I doubt that the comment is a reason of this error, but it seems that it shadows the real problem. Moreover, try to import urlparse itself and check if you got the pyc file for urlparse.py in your */lib/python2.5/ directory. -- Regards, Wojtek Walczak, http://tosh.pl/g

Re: urllib.urlopen fails in Emacs

2008-09-26 Thread Wojtek Walczak
> It works fine from the command line. Why is this happening? I can't answer your question, since I don't use emacs, but it looks like emacs has some kind of built in firewall. ;-) -- Regards, Wojtek Walczak, http://tosh.pl/gminick/ -- http://mail.python.org/mailman/listinfo/python-list

Re: how to replace and string in a "SELECT ... IN ()"

2008-09-26 Thread Wojtek Walczak
WHERE titem.object_id IN (%s) > """,( eid_list)) ^ It should rather be '%'. HTH. -- Regards, Wojtek Walczak, http://tosh.pl/gminick/ -- http://mail.python.org/mailman/listinfo/python-list

Re: setattr in class

2008-09-12 Thread Wojtek Walczak
#x27; % (i)] = i print A.xxx1 print A.xxx2 a = A() print a.xxx1 print a.xxx2 - And the output is: - 1 2 1 2 - But I definitely don't consider this one as a good programming practice. -- Regards, Wojtek Walczak, http://tosh.pl/gminick/ -- http://mail.python.org/mailman/listinfo/python-list

Re: Better error message on recursive import

2008-09-12 Thread Wojtek Walczak
t here. I can't remember any beginner asking such a question on p.c.py. I think they would come and ask if it really was problematic. And, anyway, I don't know how to answer your question :-) -- Regards, Wojtek Walczak, http://tosh.pl/gminick/ -- http://mail.python.org/mailman/listinfo/python-list

Re: how dump a program which is running in memory

2008-09-11 Thread Wojtek Walczak
lt;= 4GB of RAM. If you got more, increase it. And to make it clear: I do not recommend this way of sorting things out :) -- Regards, Wojtek Walczak, http://tosh.pl/gminick/ -- http://mail.python.org/mailman/listinfo/python-list

Re: removing text string

2008-09-10 Thread Wojtek Walczak
;080824-7 > 070405-6 You need to read about slice indices. An example: >>> a=('080829-7_A', '070529-5_c', '080824-7_O') >>> [i[:-2] for i in a] ['080829-7

Re: Reading binary data

2008-09-10 Thread Wojtek Walczak
d(11)) to check what does struct.unpack return. I guess it returns more than three elements. Just like below: >>> a,b,c=(1,2,3,4) Traceback (most recent call last): File "", line 1, in ? ValueError: too many values to unpack As you can see the fourth element from the tuple

Re: md5 differences

2008-09-10 Thread Wojtek Walczak
same for vast majority of us ;-) The question is why is it '90364ed45b452d43378629c20543a81d' for the OP? :-) -- Regards, Wojtek Walczak, http://tosh.pl/gminick/ -- http://mail.python.org/mailman/listinfo/python-list

Re: md5 differences

2008-09-10 Thread Wojtek Walczak
the file to md5.new, but the contents of this file. The strange thing is that >>> md5.new("/Volumes/data/Arno/test.txt").hexdigest() returns '8dd66a1592e2a8c3ab160822fb237f4d' on my machine. -- Regards, Wojtek Walczak, http://tosh.pl/gminick/ -- http://mail.python.org/mailman/listinfo/python-list

Re: dict slice in python (translating perl to python)

2008-09-10 Thread Wojtek Walczak
n"; What about: >>> myhash={'one':1, 'two':2, 'three':3} >>> map(myhash.get, ['one', 'two', 'two']) [1, 2, 2] >>> or, to make it more similar to perl's qw() thing: >>> map(myhash.get, 

Re: Cathing several potential errors?

2008-09-06 Thread Wojtek Walczak
On Sat, 6 Sep 2008 15:13:45 -0700 (PDT), cnb wrote: > if i do > try: > something > except TypeError, IndexError: > pass Parenthesize them: except (TypeError, IndexError): -- Regards, Wojtek Walczak, http://tosh.pl/gminick/ -- http://mail.python.org/mailman/listinfo/python-list

Re: String/Number Conversion

2008-09-06 Thread Wojtek Walczak
for giga). I'm trying > to convert those strings to integers, with this function: > if mult is 1: ^^ You're testing for identity, not for equality. Change it to "if mult == 1". Is it alright now? -- Regards, Wojtek Walczak, h

Re: max(), sum(), next()

2008-09-04 Thread Wojtek Walczak
returns an empty list, and sum([]) doesn't return an error. What did you expect? -- Regards, Wojtek Walczak, http://tosh.pl/gminick/ -- http://mail.python.org/mailman/listinfo/python-list

Re: overwrite set behavior

2008-09-04 Thread Wojtek Walczak
raise ValueError("attribute already set") self._attr1flag = True self._attr1 = x def getatt(self): return self._attr1 attr1 = property(getatt, setatt) a = SetOnce() a.attr1 = 1 print a.attr1 try: a.attr1 = 2 except ValueError: print a.attr1 --- $ pyt

Re: Issue warning if no "return" in function?

2008-09-04 Thread Wojtek Walczak
akes? Check pychecker or figleaf: http://pychecker.sourceforge.net http://darcs.idyll.org/~t/projects/figleaf/doc/ -- Regards, Wojtek Walczak, http://tosh.pl/gminick/ -- http://mail.python.org/mailman/listinfo/python-list

Re: overwrite set behavior

2008-09-04 Thread Wojtek Walczak
rcn.com/python/download/Descriptor.htm -- Regards, Wojtek Walczak, http://tosh.pl/gminick/ -- http://mail.python.org/mailman/listinfo/python-list

Re: Looking for File comparison utility that produces actual differences

2008-09-03 Thread Wojtek Walczak
or 0 i.e whether the 2 files differ or not? In python it's called difflib. Try to import it. -- Regards, Wojtek Walczak, http://tosh.pl/gminick/ -- http://mail.python.org/mailman/listinfo/python-list

Re: properties setting each other

2008-09-03 Thread Wojtek Walczak
On Wed, 3 Sep 2008 14:31:17 + (UTC), Wojtek Walczak wrote: > class Square(object): >def __init__(self, val): > self._square = pow(val, 2) > self._value = math.sqrt(self.square) ^^ or just: self._value = val :-)

Re: properties setting each other

2008-09-03 Thread Wojtek Walczak
property(getvalue, setvalue) a = Square(5) print a.square print a.value a.value = 10 print a.square print a.value a.square = 64 print a.square print a.value --- and the result: $ python sqval.py 25 5.0 100.0 10 64 8.0 $ -- Regards, Wojtek Walczak, http://tosh.pl/gminick/ -- http://mail.python.org/mailman/listinfo/python-list

Re: python - mechanize/browser/POST issue

2008-09-03 Thread Wojtek Walczak
ave a short chunk of code that I can observer, that uses the > mechanize.Browser implentation? Take a look at the bottom of this post: http://mail.python.org/pipermail/python-list/2006-June/390037.html It seems that submit does the job. -- Regards, Wojtek Walczak, http://tosh.pl/gminick/ --

Re: What is module initialization?

2008-09-02 Thread Wojtek Walczak
On Tue, 2 Sep 2008 15:32:07 +0100, [EMAIL PROTECTED] wrote: > But if I do :- >#question.py > from myglobals import * > myglobals.answer = "WTF ?" > > will this work? Why won't you try? In this case you should receive NameError. -- Regards, Wojtek Walczak

Re: Storing Subprocess Results

2008-09-02 Thread Wojtek Walczak
above assigns the output variable with a return code, i.e. 0 in > this case. How can I actually capture the data returned from > subprocess.call, rather than just the return code? Use subprocess.Popen instead of call. -- Regards, Wojtek Walczak, http://tosh.pl/gminick/ -- http://mail.python.org/mailman/listinfo/python-list

Re: Algorithm used by difflib.get_close_match

2008-09-02 Thread Wojtek Walczak
es that "look right" to people. HTH. -- Regards, Wojtek Walczak, http://tosh.pl/gminick/ -- http://mail.python.org/mailman/listinfo/python-list

Re: Getting an objetcs dict?

2008-09-01 Thread Wojtek Walczak
-questions.html HINT: the attribute you're accessing is not a callable. -- Regards, Wojtek Walczak, http://tosh.pl/gminick/ -- http://mail.python.org/mailman/listinfo/python-list

Re: Eleganz way to get rid of \n

2008-09-01 Thread Wojtek Walczak
; a="some string\r\n" >>> a.rstrip() 'some string' >>> but be careful, because it will also cut whitespaces: >>> a="some string\t \r\n" >>> a.rstrip() 'some string' >>> so maybe you could do

Re: how to find position of dictionary values

2008-09-01 Thread Wojtek Walczak
i change the key to something like 'sabir' and kev['sabir'] = kev['kabir'] del kev['kabir'] > how can i > change the values of kabir? kev['sabir'][0] = '[EMAIL PROTECTED]' *untested* -- Regards, Wojtek Walczak, http://tosh.pl/gminick/ -- http://mail.python.org/mailman/listinfo/python-list

Re: list + dictionary searching

2008-09-01 Thread Wojtek Walczak
Give it a try. Try to design some functions that let you view and add new lists/dictionaries to your variables. -- Regards, Wojtek Walczak, http://tosh.pl/gminick/ -- http://mail.python.org/mailman/listinfo/python-list

Re: Processes in Linux from Python

2008-09-01 Thread Wojtek Walczak
in pp.pids: ...if pp.procs[pid]['cmd'] == 'apache2': ... print pp.procs[pid]['tid'] ... 5204 5205 5206 5208 >>> it prints the PIDs of all the apache2 processes on my system. Procpy is fine for my own needs, but if I were about to write a code that is in

Re: How can we get to the end of a quote inside a string

2008-08-31 Thread Wojtek Walczak
some extent you can use regular expressions: >>> re.findall(re.compile("\".*?\""), s) ['" c1\' d1 \' c2"'] >>> re.findall(re.compile("\'.*?\'"), s) ['\' b1 " c1\'', '\' c2" b2 \''] >>> but it won't work in all cases. You can read more here: http://www.gnosis.cx/TPiP/ -- Regards, Wojtek Walczak, http://tosh.pl/gminick/ -- http://mail.python.org/mailman/listinfo/python-list

Re: Relative imports and "import X as Y"

2008-08-31 Thread Wojtek Walczak
conflicts in who knows what ways. Then you can download tar.gz package, compile it, and try it without installing :-) -- Regards, Wojtek Walczak, http://tosh.pl/gminick/ -- http://mail.python.org/mailman/listinfo/python-list

Re: Importing module with name given as a variable

2008-08-30 Thread Wojtek Walczak
the normal import call: import sys is equal to: sys = __import__('sys') If you need, let's say, to search for a module that lies outside sys.module paths, then use imp's functions. HTH. -- Regards, Wojtek Walczak, http://tosh.pl/gminick/ -- http://mail.python.org/mailman/listinfo/python-list

Re: class definition syntax

2008-08-29 Thread Wojtek Walczak
object class. Check out point 9.5 in the tutorial. -- Regards, Wojtek Walczak, http://tosh.pl/gminick/ -- http://mail.python.org/mailman/listinfo/python-list

Re: passing arguments to exec

2008-08-25 Thread Wojtek Walczak
On Mon, 25 Aug 2008 06:31:53 -0700 (PDT), Alexandru Mosoi wrote: > i want to execute a python script using exec open('script.py'). how do > I pass arguments? Take a look at subprocess module. It comes with a set of examples. -- Regards, Wojtek Walczak, http://tosh.pl/

Re: How to check in CGI if client disconnected

2008-08-24 Thread Wojtek Walczak
developer, but I think that the only way is to set a timeout on server side. You can't be sure that the client disconnected, but you can stop CGI script if there's no action on client side for too long. -- Regards, Wojtek Walczak, http://tosh.pl/gminick/ -- http://mail.python.org/mailman/listinfo/python-list

Re: How to know a top directory?

2008-08-23 Thread Wojtek Walczak
hat\path" then I need to get "c:\that". > > Does anyone have ideas? Read about os.path module. It's all in there: http://docs.python.org/lib/module-os.path.html -- Regards, Wojtek Walczak, http://tosh.pl/gminick/ -- http://mail.python.org/mailman/listinfo/python-list

Re: Generators can only yield ints?

2008-08-22 Thread Wojtek Walczak
port string def letters(): a, B = (string.letters,) * 2 for i in zip(a, B): yield i[0] yield i[1] l = letters() print l.next() print l.next() print l.next() -- and the output: $ python genlet.py a a b $ Is that what you tried to achieve? -- Regards, Wojtek Walczak, http://tosh.pl/gminick/ -- http://mail.python.org/mailman/listinfo/python-list

Re: Generate alphabet?

2008-08-22 Thread Wojtek Walczak
generate something if it's accessible anyway: import string print string.letters -- Regards, Wojtek Walczak, http://tosh.pl/gminick/ -- http://mail.python.org/mailman/listinfo/python-list

Re: Python one-liner??

2008-08-22 Thread Wojtek Walczak
-c? -- http://mail.python.org/mailman/listinfo/python-list

Re: 'While' question

2008-08-22 Thread Wojtek Walczak
7;re iterating through the same value in inner and outer loop. Don't do that. It's hard to predict the behavior of such a code. Regarding break statement, it breaks only the inner loop and returns to the outer loop/block. It would be great if you could reduce your code to a short pie

Re: EOF

2008-08-22 Thread Wojtek Walczak
.write(retval) should do the job. -- Regards, Wojtek Walczak, http://tosh.pl/gminick/ -- http://mail.python.org/mailman/listinfo/python-list

Re: exception handling in complex Python programs

2008-08-22 Thread Wojtek Walczak
many people, that we should just forget it. -- Regards, Wojtek Walczak, http://tosh.pl/gminick/ -- http://mail.python.org/mailman/listinfo/python-list

Re: def X(l=[]): weirdness. Python bug ?

2008-08-22 Thread Wojtek Walczak
omes on c.l.py and asks about it. -- Regards, Wojtek Walczak, http://tosh.pl/gminick/ -- http://mail.python.org/mailman/listinfo/python-list

Re: def X(l=[]): weirdness. Python bug ?

2008-08-22 Thread Wojtek Walczak
ut couldn't find it. YOURFUNCTION.func_globals['YOURFUNCTION'].func_defaults -- Regards, Wojtek Walczak, http://tosh.pl/gminick/ -- http://mail.python.org/mailman/listinfo/python-list

Re: def X(l=[]): weirdness. Python bug ?

2008-08-22 Thread Wojtek Walczak
//www.python.org/doc/faq/general/ Question 4.22. -- Regards, Wojtek Walczak, http://tosh.pl/gminick/ -- http://mail.python.org/mailman/listinfo/python-list

Re: 'While' question

2008-08-21 Thread Wojtek Walczak
o I overcome this, and make the script skip the empty files? > (should I use another command?) > 2) how do I interrupt the code without closing Python? (I have ActivePython) Try the docs first. You need to read about 'continue' and 'break' statements: http://docs.python.org/

Re: subprocess seems to "detach" / ignore wait()

2008-08-20 Thread Wojtek Walczak
pens if you change: fpid.write(child.pid) into: fpid.write('%d\n' % (child.pid)) I think that the problem here is that fpid.write() fails silently (probably TypeError), because it takes string as its first argument, not integer. -- Regards, Wojtek Walczak, http://tosh.pl/gminick/ -- http://mail.python.org/mailman/listinfo/python-list

Re: TRying to read sercah results from googles web page

2008-08-20 Thread Wojtek Walczak
eforge.net/mechanize/ FYI and AFAIK, google doesn't allow to use their search engine in this way. They even block certain IP addresses it it's constantly abusing the search engine with too many requests. -- Regards, Wojtek Walczak, http://tosh.pl/gminick/ -- http://mail.python.org/mailman/listinfo/python-list

Re: Storing Passwords

2008-08-20 Thread Wojtek Walczak
led chilkat and it looks like this library provides some 3des functionality. HTH. -- Regards, Wojtek Walczak, http://tosh.pl/gminick/ -- http://mail.python.org/mailman/listinfo/python-list

Re: [tarfile] Difficultis catching an exception

2008-08-20 Thread Wojtek Walczak
s EOFError attribute? Try this: ... except (tarfile.TarError, EOFError): ... -- Regards, Wojtek Walczak, http://tosh.pl/gminick/ -- http://mail.python.org/mailman/listinfo/python-list

Re: searching through a string and pulling characters

2008-08-19 Thread Wojtek Walczak
On Mon, 18 Aug 2008 15:34:12 -0700 (PDT), Alexnb wrote: > Also, on a side-note, does anyone know a very simple dictionary site, that > isn't dictionary.com or yourdictionary.com. This one is my favourite: http://www.lingro.com/ -- Regards, Wojtek Walczak, http://tosh.pl/gmini

Re: searching through a string and pulling characters

2008-08-18 Thread Wojtek Walczak
On Mon, 18 Aug 2008 21:43:43 + (UTC), Wojtek Walczak wrote: > On Mon, 18 Aug 2008 13:40:13 -0700 (PDT), Alexnb wrote: >> Now, I am talking 1000's of these. I need to do something like this. I will >> have a number, and what I want to do is go through this text file, just

Re: searching through a string and pulling characters

2008-08-18 Thread Wojtek Walczak
tring4)' To save some memory use finditer (as long as you don't have to search for too many of these): >>> for i in enumerate(pat.finditer(a)): ...if i[0] == 2: ... print i[1].group() ... (string3) >>> -- Regards, Wojtek Walczak, http://www.stud.umk.pl/~wojtekwa/ -- http://mail.python.org/mailman/listinfo/python-list

Re: online tutorials?

2008-08-18 Thread Wojtek Walczak
ne-Python-Books-freebooksandarticles -- Regards, Wojtek Walczak, http://www.stud.umk.pl/~wojtekwa/ -- http://mail.python.org/mailman/listinfo/python-list

Re: like a "for loop" for a string

2008-08-17 Thread Wojtek Walczak
hitespace, so it's not the same as str.split(' '). Moreover, specifying maxsplit argument whenever possible seems to be a good practice. Anyway, go ahead with that xsplit thing :-) -- Regards, Wojtek Walczak, http://www.stud.umk.pl/~wojtekwa/ -- http://mail.python.org/mailman/listinfo/python-list

Re: like a "for loop" for a string

2008-08-17 Thread Wojtek Walczak
that > gets the same result? What's "that"? Do you mean _this_: >>> somestr = "string1 string2 string3" >>> for i in somestr.split(): ...print i ... string1 string2 string3 >>> ? -- Regards, Wojtek Walczak, http://www.stud.umk.pl/~wojtekwa/ -- http://mail.python.org/mailman/listinfo/python-list

Re: how to call API Functions in python

2008-08-17 Thread Wojtek Walczak
maybe ctypes module will be helpful for you. -- Regards, Wojtek Walczak, http://www.stud.umk.pl/~wojtekwa/ -- http://mail.python.org/mailman/listinfo/python-list

Re: how many nested for can we utilize?

2008-08-17 Thread Wojtek Walczak
t;"The Effects of Moore's Law and Slacking on Large Computations" >http://arxiv.org/abs/astro-ph/9912202 Kinda buddhist approach. Anyway, it might work out, unless the number of for loops is increasing in time and in 18 months it may be - let's say - 20 nested

Re: how many nested for can we utilize?

2008-08-17 Thread Wojtek Walczak
> assuming each iteration takes a picosecond, it'll take approx 40 > billion years to run the program. I guess that's exactly why the OP asks the question. He just wants to start as soon as possible ;-) -- Regards, Wojtek Walczak, http://www.stud.umk.pl/~wojtekwa/ -- http://mail.python.org/mailman/listinfo/python-list

Re: QT, ctypes dll and SEG Faults

2008-08-17 Thread Wojtek Walczak
the one passed to __init__? Try it in __init__ to make sure: assert filename == 'your_hardcoded_value' And why won't you try to store the filename as an attribute? (even though I doubt it could help). -- Regards, Wojtek Walczak, http://www.stud.umk.pl/~wojtekwa/ -- http://mail.python.org/mailman/listinfo/python-list

Re: How do I control output buffering on Win32?

2008-08-15 Thread Wojtek Walczak
ort sys def printf(mystr): print mystr sys.stdout.flush() -- Regards, Wojtek Walczak, http://www.stud.umk.pl/~wojtekwa/ -- http://mail.python.org/mailman/listinfo/python-list

Re: getattr nested attributes

2008-08-15 Thread Wojtek Walczak
r small things and it will like you: >>> getattr(getattr(B, 'a')[0], 'test') 'test' >>> it works because: >>> getattr(B, 'a') == B.a True >>> getattr(B, 'a')[0] == B.a[0] True >>> -- Regards, Wojtek Walczak, http://www.stud.umk.pl/~wojtekwa/ -- http://mail.python.org/mailman/listinfo/python-list

Re: negative numbers are not equal...

2008-08-14 Thread Wojtek Walczak
this helps. -- Regards, Wojtek Walczak, http://www.stud.umk.pl/~wojtekwa/ -- http://mail.python.org/mailman/listinfo/python-list

Re: for y in range (0,iNumItems)--> not in order?

2008-08-14 Thread Wojtek Walczak
ses around the print instruction, it's not a function. You could also write: print "%d %d %d" % (x, y, z) -- Regards, Wojtek Walczak, http://www.stud.umk.pl/~wojtekwa/ -- http://mail.python.org/mailman/listinfo/python-list

Re: Replace Several Items

2008-08-14 Thread Wojtek Walczak
pated them correctly/incorrectly."? Don't count on it. I never really cared about being right or wrong and I am not one of those guys who are trying to prove something that actually makes no difference at all. Nice tests, though :) -- Regards, Wojtek Walczak, http://www.stud.umk.pl/~wojtekwa/ -- http://mail.python.org/mailman/listinfo/python-list

Re: Suggestion for improved ImportError message

2008-08-14 Thread Wojtek Walczak
n from >> > Python/ceval.c > > Am I correct in thinking that PyPy would mean low level > stuff like this will be Python instead of C? > That would be nice. I don't know PyPy, but I guess you're right here. -- Regards, Wojtek Walczak, http://www.stud.umk.pl/~wojtekwa/ -- http://mail.python.org/mailman/listinfo/python-list

Re: Replace Several Items

2008-08-13 Thread Wojtek Walczak
> > Chances are that you're wrong. At the moment my average is about 0.75 of mistake per post on comp.lang.python (please, bare with me ;-)). I strongly believe that the statement I made above won't make this number rise. :) -- Regards, Wojtek Walczak, http://www.stud.umk.pl/~wojtekwa/ -- http://mail.python.org/mailman/listinfo/python-list

Re: Suggestion for improved ImportError message

2008-08-13 Thread Wojtek Walczak
Dnia Wed, 13 Aug 2008 22:15:48 + (UTC), Wojtek Walczak napisa�(a): > Then go for it :-) You can prepare a patch and ask on python-dev > if the developers are interested. > > I was never hacking the import things on C level before, > but a hint: you have to modify import_fro

Re: Replace Several Items

2008-08-13 Thread Wojtek Walczak
ck (lambda m: ""), repeated replace, and repeated use of the form > > if ch in my_string: > my_string = my_string.replace(ch, "") > > on representative data. I don't have to, I can anticipate the results. I mentioned above that using re is the best approach, but if one really wants to use replace() multiple times (which will be slow, of course), it can be done a bit cleaner than with str.replace().replace().replace()... -- Regards, Wojtek Walczak, http://www.stud.umk.pl/~wojtekwa/ -- http://mail.python.org/mailman/listinfo/python-list

Re: Suggestion for improved ImportError message

2008-08-13 Thread Wojtek Walczak
thon/ceval.c My quick attempt: http://www.stud.umk.pl/~wojtekwa/patches/from-import-py2.5.1.patch -- Regards, Wojtek Walczak, http://www.stud.umk.pl/~wojtekwa/ -- http://mail.python.org/mailman/listinfo/python-list

Re: os.system question

2008-08-13 Thread Wojtek Walczak
ing for os.popen() goes to the bin. -- Regards, Wojtek Walczak, http://www.stud.umk.pl/~wojtekwa/ -- http://mail.python.org/mailman/listinfo/python-list

Re: Replace Several Items

2008-08-13 Thread Wojtek Walczak
27; >>> Next step would be to define your own replacing function: def my_replace(mystr, mychars, myrepl): """Replace every character from 'mychars' string with 'myrepl' string in 'mystr' string. Example: my_replace('Qwe.Asd/Zxc(', './(', 'XY') -> 'QweXYAsdXYZxcXY'""" for i in mychars: mystr = mystr.replace(i, myrepl) return mystr -- Regards, Wojtek Walczak, http://www.stud.umk.pl/~wojtekwa/ -- http://mail.python.org/mailman/listinfo/python-list

Re: os.system question

2008-08-13 Thread Wojtek Walczak
opriately. Got to investigate it further. os.popen won't return any deprecation warning in Py2.6beta2 probably because it is defined in Lib/platform.py and not in Lib/os.py and I guess that somebody has forgotten to add the warnings in there. -- Regards, Wojtek Walczak, http://www.stud.umk.pl/~wojtekwa/ -- http://mail.python.org/mailman/listinfo/python-list

Re: os.system question

2008-08-12 Thread Wojtek Walczak
and it doesn't > raise any warnings or mention anything in the doc string. I think that the deprecation warnings were added in Python 2.6. -- Regards, Wojtek Walczak, http://www.stud.umk.pl/~wojtekwa/ -- http://mail.python.org/mailman/listinfo/python-list

Re: python interpreter

2008-08-12 Thread Wojtek Walczak
the Programming FAQ: http://www.python.org/doc/faq/programming/ And keep in mind that reload() is removed in Py3k. Hope this helps. -- Regards, Wojtek Walczak, http://www.stud.umk.pl/~wojtekwa/ -- http://mail.python.org/mailman/listinfo/python-list

Re: trying to use SOCK_RAW yields error "

2008-08-12 Thread Wojtek Walczak
t; File "tcpsrv.py", line 15, in > server.bind((host,port)) > File "", line 1, in bind > socket.error: (19, 'No such device') What's the value of host variable? AFAIR it should be the name of the interface you want to bind to ('eth0', &#x

Re: trying to use SOCK_RAW yields error "

2008-08-12 Thread Wojtek Walczak
, not AF_INET. Note that you need root privileges to do so. -- Regards, Wojtek Walczak, http://www.stud.umk.pl/~wojtekwa/ -- http://mail.python.org/mailman/listinfo/python-list

Re: very rare python expression

2008-08-12 Thread Wojtek Walczak
>>> flags_set & flag2 2 >>> flags_set & flag3 0 >>> flags_set & flag4 8 >>> flags_set & flag5 0 -- Regards, Wojtek Walczak, http://www.stud.umk.pl/~wojtekwa/ -- http://mail.python.org/mailman/listinfo/python-list

Re: Looking out a module for Subversion

2008-08-12 Thread Wojtek Walczak
vailable for subversion, out of the box, that I can import > in my script? There is no such module in standard library, but you can try an external one. Check: http://pysvn.tigris.org/ -- Regards, Wojtek Walczak, http://www.stud.umk.pl/~wojtekwa/ -- http://mail.python.org/mailman/listinfo/python-list

Re: Second python program: classes, sorting

2008-08-10 Thread Wojtek Walczak
lf.score > other.score: return 1 return -1 ====== Should work fine now. -- Regards, Wojtek Walczak, http://www.stud.umk.pl/~wojtekwa/ -- http://mail.python.org/mailman/listinfo/python-list

Re: My very first python program, need help

2008-08-10 Thread Wojtek Walczak
# or shadow 'string' module if it's imported. def calculate_sum_1(string): result = '' for i in string: if i.isdigit(): result += i else: result += ' ' return sum([int(i) for i in result.split()]) def calculate_sum_2(string):

Re: how to find out if an object is a class?

2008-08-07 Thread Wojtek Walczak
Dnia Thu, 7 Aug 2008 14:36:37 -0700 (PDT), szczepiq napisa�(a): > Pardon me for most likely a dummy question but how do I find out if an > object is a class? Use types.ClassType: >>> class Q: ...pass ... >>> import types >>> isinstance(Q, types.ClassTy

Re: Books to begin learning Python

2008-08-07 Thread Wojtek Walczak
ut I wouldn't worry about this. Pythons 2.x will be around for quite some time (just as python 1.5.x is). -- Regards, Wojtek Walczak, http://www.stud.umk.pl/~wojtekwa/ -- http://mail.python.org/mailman/listinfo/python-list

Re: Books to begin learning Python

2008-08-07 Thread Wojtek Walczak
Dnia Thu, 7 Aug 2008 12:37:55 -0700 (PDT), Samir napisa�(a): > Some good online tutorials that I found really helpful include: You might find it useful: http://linkmingle.com/list/List-of-Free-Online-Python-Books-freebooksandarticles -- Regards, Wojtek Walczak, http://www.stud.umk

Re: HTTP basic authentication with form-based authentication

2008-08-07 Thread Wojtek Walczak
; form-based authentication (using cookies) *and* HTTP basic > authentication? Use ClientCookie or even better - mechanize: http://pypi.python.org/pypi/mechanize/ The docs aren't perfect, but you should easily find what you are searching for. -- Regards, Wojtek Walczak, http://www.stud.umk.p

Re: mktime overflow in March 2008?

2008-08-07 Thread Wojtek Walczak
rflowError: mktime argument out of range >>>> time module is written in C. time.mktime() function is actually only a wrapper for mktime(3) and it also has its limits. Better use datetime module instead. -- Regards, Wojtek Walczak, http://www.stud.umk.pl/~wojtekwa/ -- http://mail.python.org/mailman/listinfo/python-list

Re: Help with mechanize

2008-08-06 Thread Wojtek Walczak
it's described in the documentation. -- Regards, Wojtek Walczak, http://www.stud.umk.pl/~wojtekwa/ -- http://mail.python.org/mailman/listinfo/python-list

Re: URLs and ampersands

2008-08-05 Thread Wojtek Walczak
;>").replace("<","<") HTMLParser.py:s = s.replace("&", "&") # Must be last pydoc.py:return replace(text, '&', '&', '<', '<', '>', '>') xmlrpclib.py:s = replace(s, "&", "&") So it could be BaseHTTPServer, cgi, cgitb, difflib, HTMLParser, pydoc or xmlrpclib. Do you use any of these? Or maybe some other external module? -- Regards, Wojtek Walczak, http://www.stud.umk.pl/~wojtekwa/ -- http://mail.python.org/mailman/listinfo/python-list

Re: Check if module is installed

2008-08-04 Thread Wojtek Walczak
s of python. Take a look at this example: http://aima.cs.berkeley.edu/python/utils.html -- Regards, Wojtek Walczak, http://www.stud.umk.pl/~wojtekwa/ -- http://mail.python.org/mailman/listinfo/python-list