Re: [Tutor] I love python / you guys :)

2009-11-16 Thread OkaMthembo
Stefan, you echoed my thinking too :)

On Mon, Nov 16, 2009 at 8:58 AM, Stefan Lesicnik ste...@lsd.co.za wrote:

 hi,

 Although not a question, i just want to tell you guys how awesome you are!

 I am not a programmer, i can do a bit of bash. I have never officially
 learnt programming, but numerous times looked at some perl, c, java
 and never really gotten past the beginning stages of it. That all
 changed when i picked up python. Although my style and use of python
 is probably barbaric at best, I really enjoy it when you can make
 things work. Python was just amazing from a readability / logical
 point of view. If i can think of something, there is a way to do it in
 python. After learning the simple data structures it seems i can
 really do anything i want to.

 I really appreciate all the effort the knowledgeable guys put into
 this list (you know who you are! you post answers all the time!). I've
 asked a couple of questions and the answers have always been excellent
 and i've learnt so much.

 So i guess i just wanted to say thanks for supporting a great
 language, and helping me as i learn to shape my thinking into better
 and better ways to do things.

 stefan
 ___
 Tutor maillist  -  Tutor@python.org
 To unsubscribe or change subscription options:
 http://mail.python.org/mailman/listinfo/tutor




-- 
Regards,
Lloyd
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] I love python / you guys :)

2009-11-16 Thread bibi midi
On Mon, Nov 16, 2009 at 1:58 AM, Stefan Lesicnik ste...@lsd.co.za wrote:

 hi,

 Although not a question, i just want to tell you guys how awesome you are!

 I am not a programmer, i can do a bit of bash. I have never officially
 learnt programming, but numerous times looked at some perl, c, java
 and never really gotten past the beginning stages of it. That all
 changed when i picked up python. Although my style and use of python
 is probably barbaric at best, I really enjoy it when you can make
 things work. Python was just amazing from a readability / logical
 point of view. If i can think of something, there is a way to do it in
 python. After learning the simple data structures it seems i can
 really do anything i want to.



Hi Stefan,

Your message mirrored my current state. There's TONS to learn in linux like
bash, perl, vim, sed, awk, python, etc. Too much to put in your head and in
the end makes you half-baked e.g. good at start but fades away in the end.
Anyway i hope to follow your lead and be one among the guys here
knowledgeable of the language.

In the same lines of if-you-can-think-of-anything-python-can-do-it i got
inspired to ask a question for the gurus:

When i use our company's LAN i set my proxy variable by hand in .bashrc.
There are 4 files to insert proxy variable:

in ~/.bashrc, /root/.bashrc, /etc/wgetrc and /etc/apt/apt.conf.

The last one is actually rename e.g. mv to apt.conf to activate proxy and mv
to apt.conf.bak to deactivate. The proxy variable is something like this

export http_proxy=http://username:passw...@proxy:port
ftp_proxy=$http_proxy

To activate i uncomment them then source .bashrc. To deactivate i put back
the comment sign. I do it all in vim e.g. vim -o the-3-files-above. For
apt.conf see rename above. I deactivate because i have another internet
connection option via 3G usb modem. But thats another story.

I will do this myself in python so please show me the way. Surely this can
be done.



-- 
Best Regards,
bibimidi
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] I love python / you guys :)

2009-11-16 Thread Luke Paireepinart
Accidental off-list reply.
On Mon, Nov 16, 2009 at 5:36 AM, bibi midi bibsmen...@gmail.com wrote:


 In the same lines of if-you-can-think-of-anything-python-can-do-it i got
 inspired to ask a question for the gurus:

 When i use our company's LAN i set my proxy variable by hand in .bashrc.
 There are 4 files to insert proxy variable:

 in ~/.bashrc, /root/.bashrc, /etc/wgetrc and /etc/apt/apt.conf.

 The last one is actually rename e.g. mv to apt.conf to activate proxy and
 mv to apt.conf.bak to deactivate. The proxy variable is something like this

 export http_proxy=http://username:passw...@proxy:port
 ftp_proxy=$http_proxy

 To activate i uncomment them then source .bashrc. To deactivate i put back
 the comment sign. I do it all in vim e.g. vim -o the-3-files-above. For
 apt.conf see rename above. I deactivate because i have another internet
 connection option via 3G usb modem. But thats another story.

 I will do this myself in python so please show me the way. Surely this can
 be done.

 Sure it can.

This is actually fairly easy to do.  I would just use regular expressions to
match the lines and comment/uncomment them  depending on if you want to
enable/disable.



Spoiler alert! don't read if you want to solve it yourself.


 Remove/Add comments to any line that matches a specified regular
expression.
##comments are assumed to be the '#' symbol.
 Warning - completely untested code.

import re
regex =  # remove leading spaces and the # comment symbol from a line, if it
exists.

def uncomment(filename, regex, newfile):
remove_comments_regex = ' *#*(.*$)'
for line in open(filename):
if re.match(regex, line): # if we have a matching line we should
remove the comment.
newfile.write(re.match(remove_comments_regex, line).groups()[0])

def comment(filename, regex, newfile):
for line in open(filename):
if re.match(regex, line):
#avoid dual-commenting
if line.strip().startswith(#):
newfile.write(line)
else:
newfile.write('#' + line)


End of spoiler



As for renaming, look into the os module, there's an easy function for
renaming in there.  Just add a check around the rename function for an
os.path.exists(...) so you can ensure the file exists before you attempt to
rename it, otherwise you might get an exception (or you could just try
renaming it and just catch the exception, either way.)   Then just make a
.py script that can enable and one that can disable, and make sure tehre's
no harm if you run either one multiple times consecutively.

Hope that helps, and yes, we know you guys appreciate the help, that's why
we do it!  We certainly don't get paid anything.  It's nice to hear you say
it anyway though, so thanks!
-Luke
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] I love python / you guys :)

2009-11-16 Thread Stephen Nelson-Smith
Hello all,

On Mon, Nov 16, 2009 at 6:58 AM, Stefan Lesicnik ste...@lsd.co.za wrote:
 hi,

 Although not a question, i just want to tell you guys how awesome you are!

+1

I've been a happy member of this list for years, even though I've
taken a 3 year Ruby sabbatical!

I've always found it to be full of invaluable advice, and is, in my
opinion, a real gem in Python's crown.  It's one of the reasons I feel
so confident in recommending python to anyone - they can be guaranteed
a friendly and informational welcome on this list.

Thank you very much - it is greatly appreciated.

S.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor