Victor Rex | 1 Feb 2005 01:01

Re: carriage return on windows

Orri Ganel wrote:

> Jacob S. wrote:
>
>> Thanks Kent and Max!!!!!
>>
>> Wow, I didn't know it did that. I'm too dumb to figure it out on my 
>> own I guess...
>> Oh well! I found a cool new thing to play with at least!
>>
>> Thanks,
>> Jacob
>>
>>
>>
>>>
>>> On Jan 30, 2005, at 02:40, Jacob S. wrote:
>>>
>>>> I don't think that's what he wants. I think he wants to *overwrite* 
>>>> what's in the shell with new output.
>>>> For example.
>>>>
>>>>
>>>> so that the whole line is overwritten. In my experience, this is 
>>>> not possible and if anyone can show me how to do it,
>>>> I would be grateful.
>>>>
>>>> HTH,
>>>> Jacob
>>>
(Continue reading)

Bill Mill | 1 Feb 2005 01:13
Picon
Gravatar

Re: Comparing files, Counting Value

Michiyo,

When you ask a question to the list, you should be more careful to
highlight your problem so that it doesn't seem like you're asking
people to write a script for you. I don't think that's what you were
doing, but just try to reduce your problem to a minimal example in the
future.

I don't know what your script is doing; array[0, 2] is not legal as
far as I know in python (it is legal on numarray.array types, but not
on regular python lists AFAIK). I also don't know what that "in i"
stuff you're doing means. When I run your code, I get a "TypeError:
list indices must be integers" on the fields[0, 1] line. You should
try to write your code in small bites to make it easier to debug.

That said, I dig doing this sort of text processing, so I wrote my own
script to do it. Perhaps it'll help clear up some ideas for you; if
you have any questions, feel free to ask me about them:

==========begin file testprocess.py=====================
one = open('one')
two = open('two')
out = open('out', 'w')

THRESHOLD = .05

#build dict of {(x,y): z} from 'one'
pts = {}
for line in one:
    x, y, z = [float(i) for i in line.split()]   #convert strings to floats
(Continue reading)

Kent Johnson | 1 Feb 2005 01:18
Gravatar

Re: carriage return on windows

Victor Rex wrote:
> I played around with this output issue and I love the way it works.
> Now, how do you do this in *nix? I tried the same approach and I get a 
> blank line for 5 seconds (or whatever number of cycles you have on your 
> example) and the a final line with the last value of the iterable.

It sounds like the '\r' is erasing the line, not just moving the cursor. Try putting the '\r' at the 
beginning of the output rather than the end:

for i in range(10):
   print '\r', 'i is', i
   time.sleep(1)

Kent

_______________________________________________
Tutor maillist  -  Tutor <at> python.org
http://mail.python.org/mailman/listinfo/tutor

Picon

Re: Traffic Network simulator

Hi,

Don't know if there's any network simulator.

But I know about SimPy:
http://simpy.sourceforge.net/

Looks well documented. Check the examples, it seems you can do pretty
robust things with not toomuch code.
I readed about it in the charming python section of IBM developers works:
http://www-106.ibm.com/developerworks/linux/library/l-simpy.html?dwzone=linux

Check also the SimPy Wiki:
http://www.mcs.vuw.ac.nz/cgi-bin/wiki/SimPy?SimPy

Enjoy,

Guille

On Mon, 31 Jan 2005 14:50:34 -0800 (PST), Shitiz Bansal
<shitizb <at> yahoo.com> wrote:
> Hi,
> 
> I need a traffic network simulator(for roads) for my
> project work.I would prefer the simulator to be in
> python so that i can reprogram/modify it according to
> my needs.
> does anyone know where i can find something of the
> sort or are there any special modules available which
> can help me build one?
(Continue reading)

Danny Yoo | 1 Feb 2005 01:21
Picon

Re: Comparing files, Counting Value


Hi Michiyo,

Ok, let's take a look at the code.

> i=open("file 1") #value data
> o=open("file 2") #look-up file
> l=open("result", 'w')#result

We strongly recommend renaming these names to ones that aren't single
characters.

It's difficult to tell here what 'i', 'o', and 'l' mean, outside of the
context of the assignments.  The letters 'i' and 'o' often stand for the
words "input" and "output".  The way that you're using these as variable
names for input files will break the expectation of people who read the
code.  Futhermore, 'l' can easily be misread as 'i'.

In short, those names should be changed to something readable. This is a
pure style issue, but I think it's important as programmers to make the
code easy for humans to understand.

> results={}
>
> line=i.readline()
> line=o.readline()

This looks problematic.  The 'line' name here, by the end of these two
statements, is bound to the value of the look-up file's line.  I believe
you need to keep those values distinct.
(Continue reading)

Danny Yoo | 1 Feb 2005 02:27
Picon

Re: Better structure?


On Mon, 31 Jan 2005, Jacob S. wrote:

> I think this thing is screaming for better structure, but previous attempts
> at using oop for it have failed.

Hi Jacob,

Ok, I see one big refactoring that should help things quite a bit.
There's a large case-analysis off if/elif/elif statements that involves
'y'.  Let me just grep for the lines here:

>     if y == 'clear':
>     elif y == 'quit':
>     elif y == 'remove lines':
>     elif y == 'return lines':
>     elif y.startswith('gatl'):
>     elif y.startswith('ganl'):
>     elif y.startswith('gotl'):
>     elif y.startswith('gonl'):
>     elif y.startswith('getpt'):
>     elif y == 'regraph':

The structure can be improves by using that dispatch-table method we
talked about a few days ago.

We can't directly apply the dispatch technique, because there's a little
bit of nonuniformity.  Some of the statements compare y by equality, while
others use 'startswith' checks.  But I think we can handle it by making
everything a little bit more uniform: we can make everything an 'equality'
(Continue reading)

Paul Hartley | 1 Feb 2005 17:35

Presentation

I am trying to get Python established here in the Philippines. Currently I am in charge of operations at a business based in Manila and I have asked my IT staff to start using Python (with some success).
 
A local university has now asked that I give a talk to their IT people on Python - so here is an opportunity to spread the word and get some more converts and maybe introduce python into their computer science courses.
 
Any help I can get would be much appreciated - such as language comparisons, companies and systems that use python, debates about what python is good for (almost everything), examples of elegant code..
 
When I was a member of the Forth Interest Group in the USA we learned that Forth was used on the buggy that went to mars, that it started life controlling huge radio telescopes which only had 4k (yes 4k) of memory for both language and application.
 
Anything like the above concerning python would be useful.
 
Any other suggestions would help also, the audience will have computers, so a demonstration of small workshop would also be good - the presentation/session is for 4 hours on the 10th February.
 
Paul
 
_______________________________________________
Tutor maillist  -  Tutor <at> python.org
http://mail.python.org/mailman/listinfo/tutor
Max Noel | 1 Feb 2005 03:43
Picon
Favicon

Re: Presentation


On Feb 1, 2005, at 16:35, Paul Hartley wrote:

> When I was a member of the Forth Interest Group in the USA we learned 
> that Forth was used on the buggy that went to mars, that it started 
> life controlling huge radio telescopes which only had 4k (yes 4k) of 
> memory for both language and application.
>  
> Anything like the above concerning python would be useful.

	Well, that's probably not as awe-inspiring, but BitTorrent is written 
entirely in Python (with the wxPython graphical toolkit for the Windows 
and X11 versions, and PyObjC for the Mac OS X version). Google also use 
the language extensively, although I don't exactly know why, thanks to 
their obsession with secrecy.

	You could point out that Python's greatest strength (aside from its 
extreme readability -- unlike most people, The Whitespace Thing always 
struck me as an excellent design decision, although had I been Guido, 
I'd have forced the use of either tabs or spaces but not allowed both) 
is the fact that it's multi-paradigm. You can work procedurally, 
object-orientedly, and even in some cases functionally. And you can 
mix-and-match those 3 paradigms depending on your needs. This can be 
very useful.

	Oh, and make sure you mention iterators and list comprehensions at 
some point.

-- Max
maxnoel_fr at yahoo dot fr -- ICQ #85274019
"Look at you hacker... A pathetic creature of meat and bone, panting 
and sweating as you run through my corridors... How can you challenge a 
perfect, immortal machine?"

_______________________________________________
Tutor maillist  -  Tutor <at> python.org
http://mail.python.org/mailman/listinfo/tutor

Terry Carroll | 1 Feb 2005 04:18

Re: Presentation

On Tue, 1 Feb 2005, Paul Hartley wrote:

> When I was a member of the Forth Interest Group in the USA we learned
> that Forth was used on the buggy that went to mars, that it started life
> controlling huge radio telescopes which only had 4k (yes 4k) of memory
> for both language and application.
> 
> Anything like the above concerning python would be useful.

I just did a google on "Pyton success stories," and found this page, which 
you may find useful.

http://www.pythonology.com/success 

See also the two O'Reilley links on that page.

Since you mentioned use in space exploration, always a sexy example, I 
search for "Nasa Python" also turned up these:

 NASA Ames Processing in Python: 
http://home.badc.rl.ac.uk/astephens/software/nappy/

 Space shuttle engineers use Python to streamline mission design:
http://builder.com.com/5100-6401-1045764.html

... and others.

_______________________________________________
Tutor maillist  -  Tutor <at> python.org
http://mail.python.org/mailman/listinfo/tutor

Jacob S. | 1 Feb 2005 05:34

Re: Better structure?

>> def start():
>      .... lots of lines...
>>     global xaxis
>>     global yaxis
>
> Its traditional to put global statements at the top of the function.
> Also you only need one line to list all of the global variables
>
>>     global radiusaxis
>>     global radiusaxis2

What, like
global radiusaxis, radiusaxis2

> Similarly here., and again you can put all four in one place.
>
>>     radiusaxis2.visible = 0

> And since there is no input parameter and no return statement
> and you only call start() once...

Not true. If y == 'clear', then start is called to "redraw" the window.
Very important part.

>> def graphit(type,f,range2,step):
>>     li = curve(color=color.blue)
>>     if type in ['y','x']:
>>         x = -15
>>         radiusaxis.visible = 0
>>         radiusaxis2.visible = 0
>>         while -15 <= x <= 15:
>>             if eval(range2):
>>                 try:
>>                     a = f(x)
>>                     if -15 <= a <= 15:
>>                         if type == 'y':
>>                             li.append(pos=(x,a,0))
>>                         elif type == 'x':
>>                             li.append(pos=(a,x,0))
>>                     else:
>>                         li = curve(color=color.blue)
>>                 except:
>>                     pass
>
> This is iffy. If *anthing* happens you ignore it.
> Now suppose due to a bug you go into an infinite
> loop and you try to stop using CTRL-C -  it won't work!
>
> If you must use a catch-all except then do something
> with it - print a message at least!

I think I'll do that, but of course I'll have to add ValueError -- because 
of math domain errors on
my function. That's what the try except block is for. Otherwise I wouldn't 
need it.

> I got a sore head after that... I'll leave the rest for
> others to remark upon. :-)
>
> Alan G.

I'd send some Advil or something, but it doesn't work too well through 
email. ;-)
Thanks for the help,
Jacob Schmidt

_______________________________________________
Tutor maillist  -  Tutor <at> python.org
http://mail.python.org/mailman/listinfo/tutor


Gmane