urllib2.ProxyHandler

2006-04-18 Thread rx
I'm trying to hide my IP with the following code:

import urllib2
proxy=[urllib2.ProxyHandler({'http':'24.232.167.22:80'})]
opener=urllib2.build_opener(proxy)
f=opener.open('http://www.whatismyipaddress.com')
print f.read()

But that didn't work - my real IP showed up.

Then I made the following replacement:

proxy=[urllib2.ProxyHandler({'http':'24.232.167.22:80'})]-> 
proxy=[urllib2.ProxyHandler({'http':'foo'})]

And got the exact same result.

What am I doing wrong ?
Do I need a name instead of 24.232.167.22 ? (but this IP and some others I 
tried didn't have a name)

Thanks in advance



-- 
http://mail.python.org/mailman/listinfo/python-list


Re: extracting a substring

2006-04-19 Thread rx

> and I want to extract the numbers 531, 2285, ...,359.
>
> One thing for sure is that these numbers are the ONLY part that is
> changing; all the other characters are always fixed.
>

I'm not sure about what you mean by "always fixed" but I guess it means that 
you have n files with a fixed start and a changing ending, and m files with 
a fixed start and a changing ending, 

import re
filenames=['ac99_124.txt', 'ac99_344.txt', 'ac99_445.txt']
numbers=[]
for i in filenames:

numbers.append(int(re.compile('[^_]*_(?P[^.]*).txt').match(i).group('number')))



this sets numbers to: [124, 344, 445] 


-- 
http://mail.python.org/mailman/listinfo/python-list


Re: accessing a classes code

2006-04-19 Thread rx

"Ryan Krauss" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]

Is there a way for a Python instance to access its own code
(especially the __init__ method)?  And if there is, is there a clean
way to write the modified code back to a file?   I assume that if I
can get the code as a list of strings, I can output it to a file
easily enough.



You are talking about writing code from and to a file. I think I had a 
similar problem, because I wanted a python class to contains some persistent 
runtime variables (fx the date of last backup) I didn't found a solution in 
the python library so I wrote a little class myself:

import cPickle
class Persistent:
def __init__(self,filename):
self.filename=filename
def save(self):
f=file(self.filename, 'wb')
try:
for i in vars(self):
val=vars(self)[i]
if not i[0:2]=='__':
cPickle.dump(i,f)
cPickle.dump(val,f)
finally:
f.close()
def load(self):
f=file(self.filename)
try:
while True:
name=cPickle.load(f)
value=cPickle.load(f)
setattr(self,name,value)
except EOFError:
f.close()
f.close()


You just use it like (the file has to exist - easy to change):

p=Persistent('file.obj')
p.load()
p.a=0.12345
p.b=0.21459
p.save()


-- 
http://mail.python.org/mailman/listinfo/python-list


Re: multiline comments

2006-04-19 Thread rx

"Edward Elliott" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
> Ben Finney wrote:
>> Indeed. Using revision control means never needing to comment out
>> blocks of code.
>
> Typing (* and *) on a few line will always be quicker, easier, and less 
> confusing than any rcs diffs/restores.  Once you delete the code you can 
> no longer see it or add pieces back in without retrieving it from an 
> external store.  I'm not saying nested comments solve every problem, just 
> that there exists a certain (perhaps small) class of problems they solve 
> particularly well.
>
> Personally, I rarely leave code commented out beyond a single coding 
> session.  But my particular coding habits aren't relevant here.


Well I perfectly agree, and why make a dependence on external tools 
(IDE/CVS) if you can build it into the language with no conflicts by using 
some strange ascii combinations. I'm sure something like:

a()
(#
b()
c()
#)
d()

would be fine. 


-- 
http://mail.python.org/mailman/listinfo/python-list


Re: multiline comments

2006-04-19 Thread rx

"Jorge Godoy" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
> Edward Elliott wrote:
>

>
> You can use either """ or '''.  I don't keep changing them in my code, so 
> I
> can always use the other type (usually I use " so for commenting things 
> out
> I'd use ') to do that.
>

Try that on this code:

a=3
a=a*a
b='''This is a
very long
long
text'''
print a


like:

a=3
'''
a=a*a
b='''This is a
very long
long
text'''
'''
print a



raises SyntaxError 


-- 
http://mail.python.org/mailman/listinfo/python-list


Re: multiline comments

2006-04-19 Thread rx

>
> Also, if you remove the start of the block first, then your editor might 
> not
> be highlighting anymore...  With nested comments things get even worse
> because you might miss the end of the outer block or something like that.
>
> -- 
> Jorge Godoy  <[EMAIL PROTECTED]>
>

I have commented out a lot of C++ code and miss the block feature in python 
more than I missed the nested comments in C++.
Besides nothing really strange happened.
Sometimes you just need to dissable some of the code temporarly as quickly 
as possible, and I like that it is not higlighted any more, since I will not 
look into it before I dissable the comment. 


-- 
http://mail.python.org/mailman/listinfo/python-list


Re: multiline comments

2006-04-19 Thread rx



"Jorge Godoy" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
> rx wrote:
>
>> I have commented out a lot of C++ code and miss the block feature in
>> python more than I missed the nested comments in C++.
>> Besides nothing really strange happened.
>> Sometimes you just need to dissable some of the code temporarly as 
>> quickly
>> as possible, and I like that it is not higlighted any more, since I will
>> not look into it before I dissable the comment.
>
> This is how I do it: select the lines I want to comment and ask Emacs to
> comment that region.  It is the same command and method for "n" different
> languages and I don't care if there is multiline comment support or not.
> It is really as fast as inserting /* and ending with */ (in fact, I type
> less than to achieve that since I only use three keys, counting the
> Ctrl-Space to start the block).

It would be much nicer to have it in the language since there are many 
editors and many ways to do what you do (it would also make it more easy to 
make a editor).
Besides it could be done with two keys if that really important - but I 
doubt it.
But in a way you are also right if you use more than a few languages in the 
same editor, but then again the editor would still be able to do the 
commenting if you prefered that.
I don't understand the problem - why should comments (and I hope you believe 
there should be a one line comment at least) be restricted to one line.
It doesn't work that way for if, while, for. 


-- 
http://mail.python.org/mailman/listinfo/python-list


Re: multiline comments

2006-04-19 Thread rx

>
> Of course!  You should have used """ since you already used ''' in your
> triple-quoted text.  But I'm just repeating what I already said (and kept
> above so that you can see it again).
>
> -- 
> Jorge Godoy  <[EMAIL PROTECTED]>
>

Sorry - I should have read more carefully.
I like the idea and will use it I think.
Still a little strange to newcomers that there are three ways to do the same 
and that you should be carefull to use the right '''/""" inside the comment 
else the comment will not work for some reason.

#comment

'''
comment
'''

"""
comment
""" 


-- 
http://mail.python.org/mailman/listinfo/python-list


Re: multiline comments

2006-04-19 Thread rx

"Jorge Godoy" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
> rx wrote:
>
>> I don't understand the problem - why should comments (and I hope you
>> believe there should be a one line comment at least) be restricted to one
>> line. It doesn't work that way for if, while, for.
>
> It is the minimum case that can solve a problem commenting one line -- or
> part of it as in "print '3' # print the number 3" -- or commenting 
> multiple
> lines.  It is also easier to deal with since you don't have to end your
> comment all the time.
>
> For "if", "while", "for", etc. you have ":" and the indentation.  You 
> don't
> have an "endif", "endwhile", "endfor" (so, why having an "end comment"?).
>
> -- 
> Jorge Godoy  <[EMAIL PROTECTED]>
>

There no reason why a multiple line comment couldn't be indented (then the 
indentation is the end of comment in some sense), but I don't find that 
logical - after all its my comment and I don't want python to tell me how to 
indent it. 


-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Official Python logo

2006-04-19 Thread rx

<[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
> Where do I find one? Is it the banner by Just van Rossum or the Picasso
> snake on python.org?
> Thanks.
>

They talk about logos - I don't know the site.

http://www.pythonology.com/logos

google python official logo
link 6 


-- 
http://mail.python.org/mailman/listinfo/python-list