[Tutor] List of lists optimization and printing.

2011-07-29 Thread Sergey
Hello.

Yes, catb.org and so on.
I was searching for some kind of finding max width in a table (a list of two
lists) and had found this mailing list.
So I want somebody to look at my code and say what can be done better from a
programmer point of view.
Just SQL like printing and writing.
I mean optimization.
I always want to know what is the best way. Thanks.
* I don't know is it good to paste 62 lines there so here's the pastie
http://pastie.org/2291721
I hope it will be monospaced.^U
I know about SQLAlchemy but I just want to have my data in plain text because I
can't find good cross-platform suites to keep contacts, many contacts. I mean
phone number, name and so on. Something for a little bit entertprise tasks.
Yes.
Thanks.
Debian bleeding edge.
Python 2.6 default. And 2.7, 3.2 too.

Site: site
Login: login
Password: password
[['site', 'login', 'password']]
[4, 5, 8]
+--+---+--+
| Site | Login | Password |
+--+---+--+
| site | login | password |
+--+---+--+


South Africas premier free email service - www.webmail.co.za 

Save on insurance with OUTsurance
https://www.outsurance.co.za/insurance-quote/?source=webmailmailer&cr=facp11_468x60&cid=221


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


Re: [Tutor] How to replace the '\'s in a path with '/'s?

2011-07-31 Thread Sergey
Maybe something useful could be find in urllib? It can open local files. And
UNIX slashes are equal to Web slashes.
http://docs.python.org/release/3.2.1/library/urllib.request.html#urllib.request.URLopener
--
class urllib.request.URLopener(proxies=None, **x509)

Base class for opening and reading URLs. Unless you need to support opening
objects using schemes other than http:, ftp:, or file:, you probably want to use
FancyURLopener.
--

>On Sat, 30 Jul 2011 22:28:11 -0700 "Richard D. Moores" 
wrote

>I would like to write a function that would take a path 


South Africas premier free email service - www.webmail.co.za 

For super low premiums, click here http://www.dialdirect.co.za/?vdn=15828


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


Re: [Tutor] How to replace the '\'s in a path with '/'s?

2011-07-31 Thread Sergey
Gotcha!
http://pymon.googlecode.com/svn/tags/pymon-0.2/Internet/rsync.py
231-239 strings

## code ##

def convertPath(path):
# Convert windows, mac path to unix version.
separator = os.path.normpath("/")
if separator != "/":
path = re.sub(re.escape(separator), "/", path)

# Help file, folder pattern to express that it should match the all 
file or
folder name.
path = "/" + path
return path

## code ##

>On Sat, 30 Jul 2011 22:28:11 -0700 "Richard D. Moores" 
wrote



South Africas premier free email service - www.webmail.co.za 

Save on insurance with OUTsurance
https://www.outsurance.co.za/insurance-quote/?source=webmailmailer&cr=facp11_468x60&cid=221


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


Re: [Tutor] How to replace the '\'s in a path with '/'s?

2011-07-31 Thread Sergey
Haha. Works!
Happy help you.
Ask gurus about regexps. I know they have an opinion about its speed and
optimization. So they can try to criticise. But the problem is solved. It's
good. 


On Sun, 31 Jul 2011 09:18:33 -0700 "Richard D. Moores" 
wrote

> 
> Nice!
> 
> I went with
> 
> 
> import os.path
> import re
> 
> def convertPath(path):
> separator = os.path.normpath("/")
> if separator != "/":
> path = re.sub(re.escape(separator), "/", path)
> 
> return path
> 
> 
> 
> path=r'C:\Users\Dick\Desktop\Documents\Notes\College Notes.rtf'
> 
> print(convertPath(path))
> 
> """
> Output
> C:/Users/Dick/Desktop/Documents/Notes/College Notes.rtf
> """
> Dick


South Africas premier free email service - www.webmail.co.za 

For super low premiums, click here http://www.dialdirect.co.za/?vdn=15828


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


Re: [Tutor] How to replace the '\'s in a path with '/'s?

2011-07-31 Thread Sergey
Nice!
That's what I've been expecting.
Thanks.

Your one string command is tiny and complete. And elegant.
Final desicion?
Or it could be something better and more professional?
So we have removed regexps and everything is fine now. Yes?


On Mon, 01 Aug 2011 02:37:09 +1000 Steven D'Aprano  wrote

> Sergey wrote:
> > Gotcha!
> > http://pymon.googlecode.com/svn/tags/pymon-0.2/Internet/rsync.py
> > 231-239 strings
> >
> > ## code ##
> >
> > def convertPath(path):
> > # Convert windows, mac path to unix version.
> > separator = os.path.normpath("/")
> > if separator != "/":
> > path = re.sub(re.escape(separator), "/", path)
> 
> The above code is buggy. It doesn't work as expected on a classic Mac.
> Hint: import macpath; print macpath.normpath('/')
> 
> Besides, there is no need to use the 20 lb sledgehammer of regular
> expressions to crack the tiny little peanut of replacing a simple
> character with another simple character.
> 
> The above function is much more sensibly written as:
> 
> def convertPath(path):
>  separator = os.path.sep
>  if sep != '/':
>  path = path.replace(os.path.sep, '/')
>  return path
> 
> Or even more simply:
> 
>  return path.replace(os.path.sep, '/')
> 
> (although that may do a small amount of unnecessary work on Unix systems).
> 
> 
> 
> 
> --
> Steven
> 
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor




South Africas premier free email service - www.webmail.co.za 

For super low premiums, click here http://www.dialdirect.co.za/?vdn=15828


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


Re: [Tutor] Mailing list documentation

2011-07-31 Thread Sergey
On Sun, 31 Jul 2011 14:22:41 -0400 Alexander Etter  wrote

> Hello everyone, is there a page that contains documentation for this mailing
> list? I've seen a few users top post and others advise against it; if there
> isn't a page listing conventions let's create it and if there is what is it's
> URL and how do you suggest users read it?
> Alexander
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor

---
tutor-requ...@python.org
Fri, 29 Jul 2011 19:52:43 +0200(2 days, 1 hour ago)

Welcome to the Tutor@python.org mailing list! This list is for folks
who want to ask (and/or answer) questions from folks who wish to learn
how to program with Python.  Feel free to ask even the most basic of
questions -- that's what the list is for!

For best results when asking a question on this list: - Try to write
some code to solve your problem - Show the code you have written -
Describe what the code does and what you want it to do - If the code
generates an error, copy and paste the entire error message, including
the traceback, into your email. - Tell us what OS and Python version
you are using.

- Don't ask us to do your homework. - Don't assume we know what you
are talking about. If you are having trouble with a third-party
library, include a link to the library home page.

When replying to a posting: - Use Reply All to reply to the entire
list - Don't top post - put your reply after the text to which you are
replying

For all posts: - Format your email as plain text, not HTML


To post to this list, send your email to:

  tutor@python.org

General information about the mailing list is at:

  http://mail.python.org/mailman/listinfo/tutor

If you ever want to unsubscribe or change your options (eg, switch to
or from digest mode, change your password, etc.), visit your
subscription page at:

  http://mail.python.org/mailman/options/tutor/***

You can also make such adjustments via email by sending a message to:

  tutor-requ...@python.org

with the word `help' in the subject or body (don't include the
quotes), and you will get back a message with instructions.

You must know your password to change your options (including changing
the password, itself) or to unsubscribe.  It is:

***

Normally, Mailman will remind you of your python.org mailing list
passwords once every month, although you can disable this if you
prefer.  This reminder will also include instructions on how to
unsubscribe or change your account options.  There is also a button on
your options page that will email your current password to you.



South Africas premier free email service - www.webmail.co.za 

For super low premiums, click here http://www.dialdirect.co.za/?vdn=15828


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