Re: building strings from variables

2006-10-05 Thread Rainy

Gal Diskin wrote:
> Following a discussion with an associate at work about various ways to
> build strings from variables in python, I'd like to hear your opinions
> and preferred methods. The methods we discussed are:
> 1.  some_string = "cd %s ; %s  %d %s %s" % ( working_dir, ssh_cmd,
> some_count, some_param1, some_param2)
>
> 2. import string
> template = string.Template("cd $dir ; $cmd $count $param1
> $param2")
> some_string = template.substitute(dict(dir=working_dir,
>
> cmd=ssh_cmd,
>
> count=some_count,
>
> pararm1=some_param1,
>
> param2=some_param2))
> here you can use a couple of nice tricks by using class.__dict__ and
> globals() \ locals() dictionaries.
>
> 3. some_string = "cd "+working_dir+" ; "+ssh_cmd+ "
> "+str(some_count)+" "+some_param1+" "+some_param2
> (all these are supposed to produce the same strings)
>
> Which methods do you know of \ prefer \ think is better because...?
> I will appreciate any opinions about the matter.

My opinion is that 1st method is the best. It's both very readable and
easy to write. 2nd way is too involved, and 3rd way is both hard to
read and difficult to compose. Another useful variant of method #1 is
to do this: %(varname)s ..." % globals()

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


Re: Help with first script please. files, directories, autocomplete

2006-10-07 Thread Rainy

[EMAIL PROTECTED] wrote:
> Hello everyone. Hopefully someone can point me in the right direction
> here. I'm wanting to write a script to open microsoft word and adobe
> pdf documents . Here is a little background:
>
> At the company where I work (an inspection firm) all reports of
> inspections are saved as word files. A particular file may contain many
> reports named like this; 12345A-F.doc. This file contains six reports.
> Most inspections also require a technique which is saved as a pdf. The
> pdf filename is the identification of the part being inspected.
>
> My command line script will work like this: The user is asked whether
> they are searching for a technique or a report
>
> > Find (c)ertificate or (t)echnique
>
> if they press 'c' they are then asked to enter certificate number.
> Using the code below, no enter is needed
>
> import msvcrt
> print "Find (t)echnique or (c)ertificate: "
> ch = msvcrt.getch()
> if ch == 't':
>   print "Enter technique number: "
> elif ch == 'c':
>   print "Enter certificate number: "
> else:
>   print 'command not understood.'
> raw_input()
>
> Obviously I will need to wrap this into a function. What I need to know
> how to do is save the two directories where the files are stored. if
> 'c' is selected I want to use that as the directory to search. same for
> techniques. What is the best way to do this? I would also like to have
> the text autocomplete after maybe three characters, is this possible?
> Am I correct in thinking all files would have to be stored in a list
> for this to work?
>
> As you can tell I am new to programming. I don't want someone to write
> this script for me, just give me some pointers to get going (maybe a
> tutorial on the net). Unless someone really wants to write it of
> course!
>
> Many thanks and sorry for the long post.

You can store the dir name as a variable:

>>> d = 'c:\home'
>>> from os import *
>>> listdir(d)
['.Config.pm.swp', '.run.bat.swp', 'AHK scripts', 'Archive',
'Config.pm', 'Docs', 'Images', 'Links', 'Music', 'Projects', 'Python
programs', 'run.bat', 'Share', 'Torrent']

As you see files are already in a list if you use listdir function.

You can autocomplete by getting each character, running through the
list and comparing using startswith() function:

>>> l = listdir(d)
>>> m = [m for m in l if m.startswith('A')]
>>> m
['AHK scripts', 'Archive']

Then you can check how many matches you got. If you get one, print it
and ask for Enter to finalize the choice.

You might want to read tutorial on python.org. You also might want to
buy a python book, or read any number of other tutorials online if you
don't want to spend money right now. Your questions are kind of basic,
I don't want to discourage you but as you go along you will run into
many other things and it's not practical to ask every time and wait for
the answer (although people here are glad to help). 

 -Rainy

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


Re: curses problem reading cursor keys

2006-10-07 Thread Rainy

Simon Morgan wrote:
> On Sat, 07 Oct 2006 13:12:33 +, Simon Morgan wrote:
>
> > import curses
> >
> > def main(scr):
> > status = curses.newwin(1, curses.COLS, 0, 0) status.bkgd('0')
> > status.refresh()
> >
> > list = curses.newwin(curses.LINES, curses.COLS, 1, 0) list.bkgd('X')
> > list.refresh()
>
> If I use scr.subwin() instead of curses.newwin()...
>
> > y = 0
> > while True:
> > c = list.getch()
>
> and scr.getch() instead of list.getch(), things seem to work. I'd still
> really like to know what's going on though.
>
> > if c in (curses.KEY_UP, curses.KEY_DOWN, ord('z')):
> > list.addstr("Match!")
> > elif c == ord('q'):
> > break
> >
> > curses.wrapper(main)

I don't have a linux here now but I vaguely remember running into this.
I think what I did was just writing down what code you do get when
pressing down and up, etc, and using that code. By the way I looked
around back then and didn't find any thorough tutorials on curses,
either.

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


Re: A curses-game I need help with.

2006-10-10 Thread Rainy

Gasten wrote:
> Rob Wolfe wrote:
> > > while running:
> > > key_command = game.mainwin.getch()
> >
> >   # I've moved erasing messages here
> >   game.msg.ereasMsg()
>
> Man... I didn't even think of that. It's embarassing. Thanks. It works
> perfect now. Again, thanks.
>
> Gasten

By the way, I also started doing a small rogue-like with a twist that
you control monsters. I used curses, too. It's very small and
incomplete, and I think there was a bug with monsters going through
walls, but it may help you..

You can find it at silmarill.org -> programs -> I, monster.

I'd be interested in looking at your game, as it gets imporved, too, do
you have a webpage for it yet? Please post..

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


Re: Newbie question - leading zeros

2006-10-13 Thread Rainy

eldorado wrote:
> I have looked around and cannot seem to find a way to strip leading zeros
> off of values in a dictionary. Basically, I am looking to do a for loop
> and any value that has one or more leading zeros would be stripped. Any
> pointers would be appreciated. Thanks
>
> --
> Randomly generated signature
> ICMP: The protocol that goes PING!

import string
>>> string.lstrip('0001', '0')
'1'

Hope this willhelp

 -Rainy

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


Re: Ok. This IS homework ...

2006-10-14 Thread Rainy

spawn wrote:
> > Also, you never break out of your deepest loop, why are you using two
> > nested infinite-loops anyway?
> >
> > Regards,
> > Brett Hoerner
>
> Umm ..because I'm new to programming?  Actually, they do end.  If I
> move my "guess" variable outside the outermost loop, then it becomes
> infinte.  I know, I tried it.
>
> You guys are fast!  I'll reread my documentation and try a few more
> thing (I kept telling myself that running_total and subotal don't need
> to be different variables!) and see what I get.
>
> As for that last post (I don't remember your name), umm ... WOW!
> This is BEGINNING Python.  That looks far too advanced for me.

Try to think logically about how this has to be done. You need a
variable that holds the running total. You need variable that holds
user input. You need to add user input to running total and compare it
to max value. First it's often a good idea to start with pseudo-code:

loop:
  get input
  add input to running total
  if running total = goal, exit loop

what you do instead:

loop 1:
  get input
  subtotal = input
  loop 2:
get input
set running total to sum of first input and second input
if running total = goal: print 'congratulations...'

Not sure what you want to do if total gets over max value.. you want to
subtract user's next input? Or just terminate?

I think your mistake is that you tried to write code and use commands
you read about in the manual before clearly understanding what you want
the code to do. Instead of solving two problems one by one you try to
solve two problems at the same time, which is tenfold as difficult. The
first problem is understanding how the logic of program will work, and
the second, how to use commands properly to carry out that logic. Which
is fine, I make this mistake often enough..

Hope this helps.. I didn't want to write out a solution 'cause you'll
learn better if you do it on your own.

 -Rainy

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


Re: broken links on effbot.org

2006-10-14 Thread Rainy

Gerard Flanagan wrote:
> The links here seem to be broken:
>
> http://effbot.org/zone/element-index.htm#documentation
>
> I'm getting:
>
> sorry, /zone/page.cgi?page=element does not exist
>
> sorry, /zone/page.cgi?page=pythondoc-elementtree-ElementTree does not
> exist
>
> It was working two days ago, possibly yesterday (13th Oct).
> 
> Gerard

It works for me..

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


Re: invert or reverse a string... warning this is a rant

2006-10-19 Thread Rainy

Brad wrote:
> John Salerno wrote:
> > rick wrote:
> >> Why can't Python have a reverse() function/method like Ruby?
> >
> > I'm not steeped enough in daily programming to argue that it isn't
> > necessary, but my question is why do you need to reverse strings? Is it
> > something that happens often enough to warrant a method for it?
>
> I'm home for lunch so my email addy is different.
>
> No, it doesn't happen very often, but when I need to reverse something
> (usually a list or a string). I can never remember right of the top of
> my head how to do so in Python. I always have to Google for an answer or
> refer back to old code.
>
> IMO, I should be able to intuitively know how to do this. Python is so
> user-friendly most every place else... why can it not be so here?
>
> I wrote this so I'll never have to remember this again:
>
> def invert(invertable_object):
>  try:
>  print invertable_object[::-1]
>  return invertable_object[::-1]
>  except:
>  print 'Object not invertable'
>  return 1
>
> invert([1,2,3,4])
> invert('string')
> invert({1:2, 3:4})

A sequence can be reversed with a .reverse() method. For my needs, in 7
years of programming, I never needed to reverse a string. I think it
sounds like a reasonable rule of thumb to set aside things that you do
fairly often (let's say at least once a week or once in two weeks as
you write code, on average), and make sure you have shortcuts for all
of them, ways to write them quickly and easily, and make it easy to
remember as well. All other things, things you do less often, need not
be done so quickly and easily. Otherwise, I think you'll end up with a
language that has too many built in functions, methods, ins, outs and
what have you's.

If I had to reverse a string I'd first try the reverse method (although
my immediate feeling would be that it's probably not there), and then
I'd use a few lines to make a list, reverse it and join it. I don't
usually use one-liners. I would reason to myself that once in a few
years it's not a hardship to use a couple extra lines of code.

But maybe I'm missing something and in some problem domain there is a
frequent need to reverse a string? I saw your comment about countdown
on a launch of a shuttle, but that's not convincing to me, to be
honest, because if you wished to do anything as you count down (i.e.
print the next second number), you'd just make a loop and you can make
range() command reverse, or you can just reverse the list it returns.

It's a little strange; you do get a feeling that reversing a string
might be useful sometime or other, but the only thing I can think of is
palindromes, as someone else mentioned, which is used in some
textbooks. However, isn't it a little silly to add a function or a
method to language to make each textbook example into a one-liner?

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


Re: what's the difference between these two methods? (aka, why doesn't one of them work?)

2006-11-02 Thread Rainy

JohnJSal wrote:
> JohnJSal wrote:
> > Peter Otten wrote:
> >
> >
> > > ...the above is not a 1-tuple, but an ordinary string. You forgot the
> > > trailing comma:
> > >
> > > ('notes',)
> >
> > Right you are! Now it works! :)
> >
> > Thanks!
>
> Oh great, now I've moved on to another issue. It seems that the list
> appending isn't working right. All that gets added to a list is the
> last value, not everything. Am I doing something wrong with the append
> method?

Well, append method is for appending a value to a list. A single value.
You can use extend method (iirc) to extend a list with another list.

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


Re: a newbi problem: can't find complete python curses library

2006-11-02 Thread Rainy

krishnakant Mane wrote:
> hello,
> I am a new member to this list.
> I am Krishnakant from India, Mumbai.
> I have been coding in python for quite some time and now I am at the
> intermediate level of programming as far as python is concerned.
> I am going to develop a accounting software that can work on the
> console and accessed through ssh from other terminals.
> I will like to use the curses or ncurses library for the menus and the
> input forms with add, save, delete, update and cancel buttens.
> I also need to create drop down menus with a top level menu bar.
> I read a few articles about python wrapping curses but can't find some
> thing very comprehencive.
> my question is,
> does python possess a complete wrapper to ncurses and its related
> libraries like menu, panel and form?
> if yes then where can I find documentation?
> I read the python documentation and could manage to find out the
> window object but nothing on menus and panels and forms.
> thanks and regards.
> Please help,
> Krishnakant.

How about this short intro?

www.ibm.com/developerworks/linux/library/l-python6.html

It looks like it's got something about menus. Google returns many hits
for 'python curses', you might want to go through the first few pages
of results if you haven't yet.

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


Re: Ideal python idle

2006-09-24 Thread Rainy
James Stroud wrote:
> Hello,
>
> I decided that the ultimate python IDE would basically be a vim editor
> with a hotkey or button that ran the currently edited module as
> "__main__", allowing gui (tkinter, wx) windows to spawn etc.
[snip]

Hi James, I'm sure I'm missing something here, but doesn't :!python %
command run the script as __main__? It sure does spawn gui windows for
me. What exactly is the problem with using that command? It does not
return you to the line where the error happened but the runscript.vim
you mentioned doesn't seem to do that either.

-Rainy

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


Re: Ideal python idle

2006-09-24 Thread Rainy

Rainy wrote:

> [snip]

Oh, I see now that F9 designates output buffer. I usually use vim with
a log file and open the log file in a new Vim tab.

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


Re: Ideal python idle

2006-09-24 Thread Rainy

Rainy wrote:

> [snip]

Oh, I see now that F9 designates output buffer. I usually use vim with
a log file and open the log file in a new Vim tab.

-Rainy

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


Re: What is the best way to "get" a web page?

2006-09-24 Thread Rainy

Pete wrote:
> > > The file "temp.html" is definitely different than the first run, but
> > > still not anything close to www.python.org . Any other suggestions?
> >
> > If you mean that the page looks different in a browser, for one thing
> > you have to download the css files too. Here's the relevant extract
> > from the main page:
> >
> >  > type="text/css" id="screen-switcher-stylesheet" rel="stylesheet" />
> >  > rel="stylesheet" />
> >  > rel="stylesheet" />
> >  > rel="alternate stylesheet" title="large text" />
> >  > rel="alternate stylesheet" title="default fonts" />
> >
> > You may either hardcode the urls of the css files, or parse the page,
> > extract the css links and normalize them to absolute urls. The first is
> > simpler but the second is more robust, in case a new css is added or an
> > existing one is renamed or removed.
> >
> > George
>
> Thanks for the information on CSS. I'll look into that later, but now
> my question is on the first two lines of HTML code. Here's my latest
> python code:
>
> >>> import urllib
> >>> web_page = urllib.urlopen("http://www.python.org";)
> >>> fileTemp = open("temp.html", "w")
> >>> web_page_contents = web_page.read()
> >>> fileTemp.write(web_page_contents)
> >>> fileTemp.close()
>
> Here are the first two lines of temp.html:
>
>   1  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
>   2  xmlns="http://www.w3.org/1999/xhtml";>
>
> Here are the first two lines of www.python.org as saved from Firefox:
>
>   1  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
>   2 http://www.w3.org/1999/xhtml";
> lang="en">
>
> Lines one are identical. Lines two are different. Why would lines two
> differ? H...

Functionally they are the same, but third line included in Firefox.
Opera View Source command produces the same result as Python. It looks
like Firefox will do some cosmetic changes to source but nothing that
would change the way code works. Notice that attributes in second line
are re-arranged in order only?

> 
> Thanks,
> Pete

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


Problem with .next() method adding junk characters.

2006-10-01 Thread Rainy
Hi,

I tried searching for this and did not find this issue. I only looked
at about dozen hits, I apologize if this is covered somewhere and I
missed it. Without much further ado, here's the thing (Win, Py2.5):

>>> f = open('test', 'w')
>>> f.fileno()
4
>>> f.write('1\n')
>>> f.write('2\n3\n4\n')
>>> f.next()

Traceback (most recent call last):
  File "", line 1, in 
f.next()
IOError: [Errno 9] Bad file descriptor
>>> f.close()
>>> f = open('test')
>>> f.next()
'1\n'
>>> f.next()
'2\n'
>>> f.next()
'3\n'
>>> f.next()
'4\n'
>>> f.next()
'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00
...many more lines of junk...'

I'm not actually trying to do something particular, I'm making snippets
of example code for all functions in LibRef and I ran into this, and
I'm just curious as to what's happening. I understand that you're not
supposed to call .next on a file open for writing. But I don't know why
and how it does what happened here; besides, I've seen the same thing
happen before when I was doing something else with file
open/write/close, but I don't remember the specifics.

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


Re: Problem with .next() method adding junk characters.

2006-10-01 Thread Rainy

John Machin wrote:
> Rainy wrote:
> > Hi,
> >
> > I tried searching for this and did not find this issue. I only looked
> > at about dozen hits, I apologize if this is covered somewhere and I
> > missed it. Without much further ado, here's the thing (Win, Py2.5):
> >
> > >>> f = open('test', 'w')
> > >>> f.fileno()
> > 4
> > >>> f.write('1\n')
> > >>> f.write('2\n3\n4\n')
> > >>> f.next()
> >
> > Traceback (most recent call last):
> >   File "", line 1, in 
> > f.next()
> > IOError: [Errno 9] Bad file descriptor
>
> This *should* complain that the file is not open for reading. What you
> see is an accidental error. message. When I tried it, I got no error,
> but it printed a few hundred bytes of garbage.
> In both your case and mine, it has also written a load of junk to the
> file!
>
> > >>> f.close()
> > >>> f = open('test')
> > >>> f.next()
> > '1\n'
> > >>> f.next()
> > '2\n'
> > >>> f.next()
> > '3\n'
> > >>> f.next()
> > '4\n'
> > >>> f.next()
> > '\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00
> > ...many more lines of junk...'
>
> Junk was written to the file earlier.
>
> >
> > I understand that you're not
> > supposed to call .next on a file open for writing.
>
> Indeed. However if you mess up, Python is supposed to give you a
> meaningful error message and not write gibberish to your file.
>
> Please report it as a bug.
> 
> Cheers,
> John

Thanks for the reply, I reported it.. 

 -Rainy

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


Re: Problem with .next() method adding junk characters.

2006-10-02 Thread Rainy

Paul McGuire wrote:
> "Fredrik Lundh" <[EMAIL PROTECTED]> wrote in message
> news:[EMAIL PROTECTED]
> > "Rainy" <[EMAIL PROTECTED]> wrote:
> >
> >> I'm just curious as to what's happening. I understand that you're not
> >> supposed to call .next on a file open for writing. But I don't know why
> >> and how it does what happened here; besides, I've seen the same thing
> >> happen before when I was doing something else with file
> >> open/write/close, but I don't remember the specifics.
> >
> > C's stdio library require you to call "flush" when switching between
> > reading and
> > writing; if you don't, the result is undefined.
> >
> > 
> >
>
> Sure enough, following the OP's original sequence, with an intervening flush
> between the writes and next, leaves the file in the expected state:
>
> >>> f = file("xyzzy.dat","w")
> >>> f.write("1\n")
> >>> f.write("2\n")
> >>> f.write("3\n")
> >>> f.flush()
> >>> f.next()
> Traceback (most recent call last):
>   File "", line 1, in ?
> IOError: [Errno 9] Bad file descriptor
> >>> f.close()
> >>> f = file("xyzzy.dat")
> >>> f.next()
> '1\n'
> >>> f.next()
> '2\n'
> >>> f.next()
> '3\n'
> >>> f.next()
> Traceback (most recent call last):
>   File "", line 1, in ?
> StopIteration
> >>>
>
> I would guess then that the likely extent of any fix to this "bug" would be
> documentation to the effect of Fredrik's last comment above.
> 
> -- Paul

Thanks.. I get it now. Should I close the bug report then?

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


Re: Vim scripts for editing Python?

2006-11-21 Thread Rainy

Danny Colligan wrote:
> On Nov 21, 11:48 am, "Danny Colligan" <[EMAIL PROTECTED]> wrote:
> > Rainy wrote:
> > > Hi, did anyone make a good set of scripts for editing Python in Vim? I
> > > know there is one on vim.org but it isn't very advanced. thx..Here's what 
> > > google has to say about 
> > > it:http://www.google.com/search?hl=en&q=site%3Ahttp%3A%2F%2Fwww.vim.org%...http://www.google.com/search?hl=en&lr=&safe=off&q=site%3Ahttp%3A%2F%2...
> >
> > Danny
>
> Almost forgot... if you do some searching around on comp.editors for
> vim and python:
>
> http://groups-beta.google.com/group/comp.editors/search?group=comp.editors&q=vim+python&qt_g=Search+this+group
>
> You'll find some helpful threads such as this one:
>
> http://groups-beta.google.com/group/comp.lang.python/browse_thread/thread/7678e4269a806476/c65a6a9ed84e0eb2?lnk=gst&q=python&rnum=5#c65a6a9ed84e0eb2
> 
> Danny

Thanks Danny, that's exactly what I was looking for!

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


Re: Learning Python now coming from Perl

2008-12-06 Thread Rainy
On Dec 6, 5:00 am, Bertilo Wennergren <[EMAIL PROTECTED]> wrote:
> I'm planning to start learning Python now, using Python 3000.
> I have no previous Python skills, but I now Perl pretty well.
> I'm also well experienced with JavaScript.
>
> Any pointers and tips how I should go about getting into
> Python?
>
> --
> Bertilo Wennergren 

There's a lot of hoopla about Py3k being different, incompatible
with Py2.x. However, you have to keep in mind that this matters
most of all to old, large programs, which will need to be changed
if one would like to run them on Py3k. For learning the differences
don't matter much. If you learn to code in py2.x for half a year,
you will be able to pick up on most of the differences and transfer
to py3k in a few days. If you find good docs on py2.x go ahead and
use them and don't worry.
--
http://mail.python.org/mailman/listinfo/python-list


Select, interrupted system call, log rotation?

2008-12-06 Thread Rainy
I got an interrupted system call exception in select and I don't know
what could have caused it. Here's the error:

select.select(inputs, [], [], 9)
error: (4, 'Interrupted system call')
Caught an exception, shutting down...

It's py2.3, on mach architecture.

I'm trying to figure out what caused it, and the only idea I have so
far is that it could be that I have python's logging system log
rotation thing running and I think I've seen a reference somewhere
that it uses SIGALRM when log file reaches set size to stop and switch
the files. The program was running for about a week without any
problem and then I got this exception and after I restarted it it's
been running for a few days and I only got the exception once in all
that time.

Am I going in a completely wrong direction here? I'm thinking of just
putting select in try: except: , is that a good idea here?

I don't understand signals all that well. Thanks.
--
http://mail.python.org/mailman/listinfo/python-list


Re: how to get a beep, OS independent ?

2008-12-06 Thread Rainy
On Dec 6, 3:40 pm, Stef Mientki <[EMAIL PROTECTED]> wrote:
> hello,
>
> I want to give a small beep,
> for windows there's message-beep,
> and there seems to be something like " curses" ,
> but that package seems to be totally broken in P2.5 for windows.
>
> Any other suggestions ?
>
> thanks,
> Stef Mientki

For win there's winsound, you have to check sys.platform and do
what's necessary for the platform in question. In linux I think
you can just print '\a' (or does that only work in terminals?).
If you know that ext. speakers are always on, you can do a nicer
beep by using some wav file, in linux it's probably easiest to
use an external program to play it, like wavplay. Basically,
there is no single answer, it depends on circumstances.
--
http://mail.python.org/mailman/listinfo/python-list


ANN: updates to Python-by-example

2009-02-27 Thread Rainy
Python-by-example http://pbe.lightbird.net/index.html";>http://
pbe.lightbird.net has some new modules added: pickle, shelve,
sqlite3, gzip, csv, configparser, optparse, logging. I also changed
over to using excellent sphinx package to generate documentation, this
will allow me to add pdf and windows help formats soon (I ran into
some issues with that, actually). More modules coming soon, too! -AK
--
http://mail.python.org/mailman/listinfo/python-list


Separators inside a var name

2008-06-09 Thread Rainy
I have a stylistic question. In most languages words in var. name are
separated by underscores or cap letters, resulting in var names like
var_name, VarName and varName. I don't like that very much because all
3 ways of naming look bad and/or hard to type. From what I understand,
scheme can have variables like var-name. I'm curious about reasons
that python chose to disallow this. Another question I have is what
other languages allow this naming scheme? Were there any languages
that allowed space as a separator? What would be a practical way to
separate variables from keywords in that case? "some long variable
name", 'just a string', or maybe using 2 spaces: one var  +  other
var  +  third var ? I think being able to easy have very long names
for vars that are easy to type would be a fairly significant
advantage. I know I'm probably being too obsessive about this, but
that didn't stop me from posting. Comments?
--
http://mail.python.org/mailman/listinfo/python-list


Re: Separators inside a var name

2008-06-09 Thread Rainy
On Jun 9, 1:42 pm, Gary Herron <[EMAIL PROTECTED]> wrote:
> Rainy wrote:
> > I have a stylistic question. In most languages words in var. name are
> > separated by underscores or cap letters, resulting in var names like
> > var_name, VarName and varName. I don't like that very much because all
> > 3 ways of naming look bad and/or hard to type. From what I understand,
> > scheme can have variables like var-name. I'm curious about reasons
> > that python chose to disallow this.
>
> Because we'd prefer var-name to mean subtraction of values: var minus
> name.  If you want to use a that character in names, what syntax would
> you prefer for subtraction?  Do you consider lisp/scheme (- a b) to be
> reasonable in Python?

I would make it that var - var2 would be subtraction and var-name
would be
a var name. I don't like (- a b) but I might have preferred it if it
allowed dashes inside var names, if I got used to it. Hard to say.

>
> > Another question I have is what
> > other languages allow this naming scheme? Were there any languages
> > that allowed space as a separator?
>
> Fortran used to.  (Haven't checked in on it in years though so I don't
> know now).  And it not so much as allowed spaces as it *ignored* all
> spaces.  This was now-a-days considered a *really* bad idea, and is
> rumored to be responsible for a bug that crashed a satellite.  (At least
> that's the way a nice urban legend tells it.)

Well, if I understand right, fortran used caps for many things? I'm
not sure
how it separated things if it ignored all spaces. I'll trust you that
it's
not a good idea :-). However that's not what I meant, I'd just like to
use
(or rather try using) spaces inside var names.


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


Re: Separators inside a var name

2008-06-09 Thread Rainy
On Jun 9, 2:05 pm, "Sebastian \"lunar\" Wiesner"
<[EMAIL PROTECTED]> wrote:
>  Rainy <[EMAIL PROTECTED]> at Montag 09 Juni 2008 19:29:
>
> > I have a stylistic question. In most languages words in var. name are
> > separated by underscores or cap letters, resulting in var names like
> > var_name, VarName and varName. I don't like that very much because all
> > 3 ways of naming look bad and/or hard to type.
>
> Then you better get used to such names, as they are common for many widely
> spread languages including C, C++, C#, Java, Python, Ruby, Perl and many
> more ;)  You may like these or dislike these names, but you won't come
> around them ;)

Well, I was thinking of using some obscure language for personal
projects
that may not need good libs, etc. But of course I agree that there are
no mainstream widely used languages that allow this.

>
> > From what I understand, scheme can have variables like var-name. I'm
> > curious about reasons that python chose to disallow this.
>
> "-" is an operator in Python.  How should the parser know,
> whether "var-name" means "the object bound to var_dash_name" or "subtract
> the object bound to name from the object bound to var"?

As I mentioned in another post, differentiate between var1 - var2 and
var-name.

>
> Scheme can allows such names, because its a functional programming language.
> Subtracting in this language is not done through operators, but through
> functions.  Therefore there is a clear difference between referencing a
> name or subtracting two ones: var-name vs (- var name).
>
> > Another question I have is what other languages allow this naming scheme?
>
> Other lisp dialects do, due to the same reasons as scheme.  
>
> > Were there any languages that allowed space as a separator?
>
> None that I know of.  Probably one could use unicode characters, that look
> like a space in languages, which allow unicode characters in identifiers
> (as Java or C#, iirc), but I doubt this.  Anyway, even if allowed, this
> would be silly, since it obscures code to the eyes of the reader.

Yes, that's of course out. I meant using real space.

>
> > What would be a practical way to separate variables from keywords in that
> > case? "some long variable name", 'just a string', or maybe using 2 spaces:
> > one var  +  other var  +  third var ?
>
> I can't image a practical way to allow a space as character in names, while
> still maintaining it syntactic element for separation of names.  Quotes are
> normally used for string or characters literals and a double space is hard
> to distinguish from a single space, and things like ${a name with spaces}
> is a lot nastier than names with underscores (which aren't bad at all,
> imho).

I agree about ${name with spaces}. I would be interested in the
approach
of using something else for strings and using quotes for var names.
Not
perfect either but might be better than underscores...

>
> > I think being able to easy have very long names for vars that are easy to
> > type would be a fairly significant advantage.
>
> Names shouldn't be long, they should be expressive.  If you can't give an
> object a _short_, but _expressive_ name, your object is too complicated ;)

I'm not sure, I often find myself needing to use 4 words for var name,
and
then underscores I think don't look too good, I would say that
underscores
are kind of ok for 2 words, not very good for 3 words and bad for 4+
words.
I think if spaces were allowed, I would sometimes use 5 word
variables.

>
> Btw, I don't really understand your refusal of underscores.  In my opinion
> such names are harder to read than underscores, which look more like a real
> space, because the leave a space in the middle of a line, that you look at.
> If they are too hard for you to type, whats the point in swapping the dash
> and the underscore in your keyboard layout?

To me, underscores_look_very_ugly. What_if_I_typed
part_of_every_sentence
with_an_underscore? Ugly! Swapping the dash and underscore are not a
bad
idea, it doesn't fix uglyness, though, and it adds a problem if you
have
to work on another system, because you will always type dash by
mistake
(which will look nice but won't work ;-) ).

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


Re: Separators inside a var name

2008-06-09 Thread Rainy
On Jun 9, 5:45 pm, Lie <[EMAIL PROTECTED]> wrote:

>
> As Sebastian have said, it just can't work like that in python and
> most languages. var1-var2 is a subtraction, because - is an operator.
> Operator must allow spaces and lack of spaces, how would you want
> these to be interpreted then: a+b, a-b, a/b, a*b, a**b? In Lisp/Scheme

Well, a couple of things could be done, I don't really care
either way. Mind you, I of course don't think Python will
be changed in this way, I'm just curious about reasons and
whether other languages do this. That said, it could either
be allowed to have +,-,/,*,** in var name, or disallow
them unless they're surrounded by spaces. Sometimes it's
nice to use them without spaces but that's not at all
important to me.


> > > Scheme can allows such names, because its a functional programming 
> > > language.
> > > Subtracting in this language is not done through operators, but through
> > > functions.  Therefore there is a clear difference between referencing a
> > > name or subtracting two ones: var-name vs (- var name).
>
> > > > Another question I have is what other languages allow this naming 
> > > > scheme?
>
> > > Other lisp dialects do, due to the same reasons as scheme.  
>
> > > > Were there any languages that allowed space as a separator?
>
> > > None that I know of.  Probably one could use unicode characters, that look
> > > like a space in languages, which allow unicode characters in identifiers
> > > (as Java or C#, iirc), but I doubt this.  Anyway, even if allowed, this
> > > would be silly, since it obscures code to the eyes of the reader.
>
> > Yes, that's of course out. I meant using real space.
>
> Real space or space-lookalike, allowing blank characters for variable
> names is a bad idea. It hurts readability by a factor of twenty.

I'm not sure that's the case.

>
>
>
> > > > What would be a practical way to separate variables from keywords in 
> > > > that
> > > > case? "some long variable name", 'just a string', or maybe using 2 
> > > > spaces:
> > > > one var  +  other var  +  third var ?
>
> > > I can't image a practical way to allow a space as character in names, 
> > > while
> > > still maintaining it syntactic element for separation of names.  Quotes 
> > > are
> > > normally used for string or characters literals and a double space is hard
> > > to distinguish from a single space, and things like ${a name with spaces}
> > > is a lot nastier than names with underscores (which aren't bad at all,
> > > imho).
>
> > I agree about ${name with spaces}. I would be interested in the
> > approach
> > of using something else for strings and using quotes for var names.
> > Not
> > perfect either but might be better than underscores...
>
> Err.. what's actually your problem with underscore? Quoting names is
> the worse idea ever, I'm sure he only reference it as a joke.
> Especially since it would be ambiguous whether the thing in the quote
> is a name or a string

Well, that's a matter of taste, naturally, but
I don't like either to type or read underscores
between words. I think they look ugly. In regard
to strings, yes, strings would have to be
marked up differently. Maybe str(some string)?


>
>
>
> > > > I think being able to easy have very long names for vars that are easy 
> > > > to
> > > > type would be a fairly significant advantage.
>
> > > Names shouldn't be long, they should be expressive.  If you can't give an
> > > object a _short_, but _expressive_ name, your object is too complicated ;)
>
> > I'm not sure, I often find myself needing to use 4 words for var name,
> > and
> > then underscores I think don't look too good, I would say that
> > underscores
> > are kind of ok for 2 words, not very good for 3 words and bad for 4+
> > words.
> > I think if spaces were allowed, I would sometimes use 5 word
> > variables.
>
> I think you need to think simple. KISS principle.
> Add documentation then use short, expressive names.
> Generally a shorter the name is more readable than 5-words names.
>
> Which ones is clearer:
> class Math(object):
>     def add(a, b):
>         return a + b
>     def sub(a, b):
>         return a - b
>
> and:
> class Mathematic(object):
>     def addition(left_hand_side_operand, right_hand_side_operand):
>         return left_hand_side_operand + right_hand_side_operand
>     def subtraction(left_hand_side_operand, right_hand_side_operand):
>         return left_hand_side_operand - right_hand_side_operand

A well constructed strawman is always a pleasure
to behold but I think you could make a much better
strawman than this :-).

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


Re: Separators inside a var name

2008-06-09 Thread Rainy
On Jun 9, 5:34 pm, Alexander Schmolck <[EMAIL PROTECTED]> wrote:
> Rainy <[EMAIL PROTECTED]> writes:
> > I have a stylistic question. In most languages words in var. name are
> > separated by underscores or cap letters, resulting in var names like
> > var_name, VarName and varName. I don't like that very much because all
> > 3 ways of naming look bad and/or hard to type. From what I understand,
> > scheme can have variables like var-name. I'm curious about reasons
> > that python chose to disallow this.
>
> Legacy -- mathematical notation is broken and conflates negation and
> subtraction (causing all sorts of annoyances including this one). Thus if you
> want to be able to name a variable ``a-b`` you either have to write ``a - b``
> to disambiguate subtracton from the variable name ``a-b`` or you need to chose
> a different symbol for subtraction (writing "a ~ b" would likely be the best
> choice).

~ is terrible, imho, I'd much rather disallow a - b for subtraction
(and all
math ops).

>
> > Another question I have is what other languages allow this naming scheme?
>
> All lisps. Dylan. Rebol. Postscript. Forth. I'm sure there are a few others.
>
> > Were there any languages that allowed space as a separator?
>
> Sure.
>
> > What would be a practical way to separate variables from keywords in that
> > case?
>
> Lisp allows you to use pretty much anything in a variable name, you just have
> to quote it, either
>
>  like\ this
>
> or
>
>  |like this|

This is actually pretty nice. I think I like this much better
than C/Java/etc convention. I wouldn't use pipes but I'd pick
something that's easy to type and is nicely readable. Not
sure what..

>
> > "some long variable name", 'just a string', or maybe using 2 spaces: one var
> > + other var + third var ? I think being able to easy have very long names
> > for vars that are easy to type would be a fairly significant advantage.
>
> I assume you haven't programmed too much? The problem with long names is that
> they obscure structure, so they are only worthwhile for rarely used and fairly
> obscure concepts where the added descriptiveness yields a net advantage.

Only about 8 years, but it may be that I'm just
not very good ;-). I'm not sure that's the case.
My problem with long names is that they look
ugly, and the longer they are, the uglier they
look when you use underscores or caps. Other
than that, I'd like to have an option to use
longer names. Maybe it won't be used all the
time, but still..

>
> > I know I'm probably being too obsessive about this, but that didn't stop me
> > from posting. Comments?
>
> I think you're right -- the common naming convention's suck and "python's" is
> particularly bad (HtmlFrob HTMLFrob htmlFrob html_frob htmlfrob HTML_FROB
> HTMLFROB -- which one will it be? No way to know without looking at the rest
> of the code, the only consistency is that the last two are mostly used for
> constants; everything else is completely up for grabs). You'd better get used
> to it though, it's become "standardized".
>
> 'as

Well, I agree, this is terrible. If I were Guido I'd
make a very explicit rule that a certain naming
scheme is preferred and other schemes are very bad.
And I'd get it in the beginning of official tutorial,
libref, in books, etc. Mostly it's ClassName and func_name
and var_name and so on, but very often it's something else.
BUT even if that was the rule and everyone followed it,
though it would be much better than what we have now,
it would still offend my taste. Just saying!

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


Pyserial not getting response every time, input/output errors

2008-08-12 Thread Rainy
Hello!

I'm having some trouble with pyserial package, I'm sending commands
and reading responses from a custom pcb, and sometimes I get a proper
response, at other times I get nothing, and sometimes I get about half
of the response string with beginning cut off. About half the time an
empty string is returned, the other ~half time good response, and more
rarely I get partial response.

When I try to use the same Serial instance to send/receive a few
times, I end up getting an input/output error.

Here are some examples:

>>> ser = serial.Serial('/dev/ttyAM1', 115200, timeout=0.1)
>>> ser.write(chr(2) + chr(1) + chr(6) + chr(12) + chr(34) + chr(0) + chr(0))
>>> ser.read(60)
''
>>> ser.close()
>>> ser = serial.Serial('/dev/ttyAM1', 115200, timeout=0.1)
>>> ser.write(chr(2) + chr(1) + chr(6) + chr(12) + chr(34) + chr(0) + chr(0))
>>> ser.read(60)
'\x02\x00\'\x0c"\x00My Thermostat R1.0B'

>>> ser.write(chr(2) + chr(1) + chr(6) + chr(12) + chr(34) + chr(0) + chr(0))
Traceback (most recent call last):
 File "", line 1, in ?
 File "/usr/lib/python2.3/site-packages/serial/serialposix.py", line
372, in write
   n = os.write(self.fd, d)
OSError: [Errno 5] Input/output error


I tried timeout values from 0.1 to 3sec. Doesn't make a difference.

Aside from the possibility of hw issue (I'm investigating this now),
what else could it be? We tested this from a different computer from a
Ferret terminal program using a different cable, and it worked without
problem. I tried many different things, using miniterm.py provided
with pyserial, getting newest version of pyserial, sending one char at
a time, etc etc. I get same intermittent problems..

If anyone have an idea on what else I can try, please help! thanks!
--
http://mail.python.org/mailman/listinfo/python-list


Re: Pyserial not getting response every time, input/output errors

2008-08-12 Thread Rainy


Carsten Haese wrote:
> Rainy wrote:
> > Hello!
> >
> > I'm having some trouble with pyserial package, I'm sending commands
> > and reading responses from a custom pcb, and sometimes I get a proper
> > response, at other times I get nothing, and sometimes I get about half
> > of the response string with beginning cut off. About half the time an
> > empty string is returned, the other ~half time good response, and more
> > rarely I get partial response.
> >
> > When I try to use the same Serial instance to send/receive a few
> > times, I end up getting an input/output error.
> >
> > Here are some examples:
> >
> >>>> ser = serial.Serial('/dev/ttyAM1', 115200, timeout=0.1)
>
> One possible point of failure is that you're not supplying any
> parameters for the data format (byte size, parity, stop bits) and flow
> control. The Serial object will assume defaults, and those defaults may
> or may not be correct.
>
> Try to find out what data format and flow control you should be using
> and set explicit Serial parameters accordingly.
>
> Hope this helps,
>
> --
> Carsten Haese
> http://informixdb.sourceforge.net

Thanks for the reply, Carsten, I should have mentioned.. yes, I did
confirm
that defaults pyserial's providing are correct with pcb maker.
--
http://mail.python.org/mailman/listinfo/python-list


Re: do you know what's CGI? (web history personal story)

2011-01-15 Thread Rainy
On Jan 15, 5:22 pm, Alice Bevan–McGregor  wrote:
> On 2011-01-15 08:55:47 -0800, rantingrick said:
>
> > On Jan 15, 10:38 am, Grant Edwards  wrote:
>
> >>> Yeah, James Cameron made a *ton* of money using it to make Avatar.
>
> >> Too bad he couldn't have used it to make a better movie.
>
> I found the graphics impressive; the "blue people" was merely an effort
> to avoid a more clear representation of the Na'vi as North American
> indigenous people.
>
> > Avatar was very disappointing (Both in graphics and story) but maybe i
> > expect too much...?
>
> The story was clearly "Pocahontas… in Space!", which was very disappointing.
>

I have to disagree.. without writing
a dozen pages of my thoughts on Avatar,
I think this comment from Metafilter
sums it up best:

http://www.metafilter.com/88197/Even-better-without-special-effects#2897157

http://www.metafilter.com/88197/Even-better-without-special-
effects#2897157">link
-- 
http://mail.python.org/mailman/listinfo/python-list