[Tutor] any win32com experts out there?

2006-11-17 Thread Orri Ganel
Hello again. As I've mentioned in the last couple of emails, I'm having trouble registering iTunes for events, and I don't know if it's a bug with iTunes or with win32com, or if there's something I'm doing wrong. So, if any win32com gurus out there know why the following doesn't work and how

Re: [Tutor] registering itunes with events

2006-11-17 Thread Orri Ganel
Alan Gauld wrote: >"Orri Ganel" <[EMAIL PROTECTED]> wrote > > > >>been fruitless. My best guess is something along the lines of: >> >>iTunes = >>win32com.client.gencache.EnsureDispatch("iTunes.Application") >>iTunesEvents =

[Tutor] registering itunes with events

2006-11-17 Thread Orri Ganel
Hello all, As I mentioned in my recent emails, I've been working on a program that will display the currently playing iTunes track (for example, when iTunes is minimized to the system tray so that you don't have to enlarge it again just to see the name of the song). Unfortunately, of the hundreds

Re: [Tutor] removing an image from a tkinter label

2006-11-15 Thread Orri Ganel
Alan Gauld wrote: >"Orri Ganel" <[EMAIL PROTECTED]> wrote > > > >>In the end, setting lbl["image"] = "" worked >> >> > >Glad it worked. I was just about to suggest creating an image >with the "No image&q

Re: [Tutor] removing an image from a tkinter label

2006-11-14 Thread Orri Ganel
Orri Ganel wrote: Hello all, As part of a tkinter program that displays the currently playing track's information (including artwork) from iTunes, I have a label with an image in it (the artwork). However, when the song played doesn't have artwork, I'd like to remove art

[Tutor] removing an image from a tkinter label

2006-11-14 Thread Orri Ganel
Hello all, As part of a tkinter program that displays the currently playing track's information (including artwork) from iTunes, I have a label with an image in it (the artwork).  However, when the song played doesn't have artwork, I'd like to remove artwork of the old song and replace it with

Re: [Tutor] : finding out if the horizontal scrollbar on a Tix.CheckList is being used or not

2006-07-21 Thread Orri Ganel
As a follow up to my last email, I think the issue is more that the display doesn't update before the command associated with the "search" button has finished processing, so any attempts to get data about the display from within the method are fruitless since the display hasn't changed yet. I

[Tutor] : finding out if the horizontal scrollbar on a Tix.CheckList is being used or not

2006-07-21 Thread Orri Ganel
Hello all, I'm working on the GUI for my extended iTunes search, which allows searches far beyond the native iTunes capability. Once the search has been completed, a window contining a Tix.CheckList with the resulting tracks is displayed. If anyone has any idea how to figure out whether or

Re: [Tutor] : finding out if the horizontal scrollbar on a Tix.CheckList is being used or not

2006-07-21 Thread Orri Ganel
Oops, please send any questions to this email, not the one I sent the last message with. Thanks, Orri ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] How to make the loop work?

2006-06-22 Thread Orri Ganel
Ivan Low wrote: >Bob Gailer wrote: > > >>Ivan Low wrote: >> >> >>>Hi, I'm new to python trying to figure how to make this work. >>> >>>c=0;d=raw_input("input number limit: ") >>> >>>while 1: >>>c = c + 1 >>>if c == d: break >>>print c, >>> >>> >>>My idea is to able to input a num

[Tutor] [Fwd: Re: for loops over multiple lists of the same length]

2006-06-22 Thread Orri Ganel
Oops, forgot to reply to the list; sorry everyone. -- Email: singingxduck AT gmail DOT com AIM: singingxduck Programming Python for the fun of it. --- Begin Message --- Emily Fortuna wrote: Thanks, I knew there had to be a really simple way to do it. Emily Orri Ganel wrote: Emily Fortuna

Re: [Tutor] How do I create the equivalent of a Java class in Python?

2006-05-16 Thread Orri Ganel
Alan Gauld wrote: > > How do I create the equivalent of a Java class in Python? I've been > looking > > at the reference, and it's been confusing to me at least. > > Adapted from my book: > > Java code: > > class Msg{ >private String txt; >public Msg(String s){ > this.txt = s;

Re: [Tutor] Bigrams and nested dictionaries

2006-04-03 Thread Orri Ganel
My only comment is that this considers spaces and punctuation (like parentheses, brackets, etc.), too, which I assume you don't want seeing as how that has little to do with natural languages.  My suggestion would be to remove the any punctuation or whitespace keys from the dictionary after you've

Re: [Tutor] request for sugestions on fragement of code for generating truth-tables

2006-04-01 Thread Orri Ganel
Brian van den Broek wrote: >Hi all, > >I've been too busy with life to do much Python of late. So, I am a bit >rusty. :-( > >I've got some code that does what it needs to but I think I might be >overlooking a much smoother way to get what I need. > >The code takes a list of strings and returns a

Re: [Tutor] Data Type with Dictionary and List Behavior

2006-03-28 Thread Orri Ganel
Carroll, Barry wrote: >Greetings: > >I have a function that computes the checksum of an integer, including or >excluding digits in the computation based on the content of a mask string. >For example, > >cksum(123456789, '***...***') > >will do its computation on 123789, masking out the thr

Re: [Tutor] 'in-place' methods

2006-02-17 Thread Orri Ganel
Michael Broe wrote: >I think I understand this sorting-a-list 'in place' stuff, and things >of that kind (reversing for example); but I am finding it very >difficult to get used to, since sorting a list doesn't return the >sorted list as a value, but simply does the work as a side effect. >

Re: [Tutor] [newbie alert] why can't I find a function that gives me the sign of an integer?

2006-01-26 Thread Orri Ganel
rt1) >>> temp [(40, 18, 90), (32, 21, 39), (14, 22, 2), (15, 67, 15), (16, 70, 87), (60, 78, 35), (57, 80, 33), (21, 92, 69), (70, 95, 39), (3, 98, 7)] >>> temp.sort(cmp=sort2) >>> temp [(14, 22, 2), (3, 98, 7), (15, 67, 15), (57, 80, 33), (60, 78, 35), (32, 21, 39), (70, 9

Re: [Tutor] [newbie alert] why can't I find a function that gives me the sign of an integer?

2006-01-26 Thread Orri Ganel
Rinzwind wrote: In basic I can use SGN to get back -1, 0,  +1 if a number is <0, 0, >0. I searched on  the web for a bit but sgn and sign give me way too many discussions about Decimals. python.org with numbers/digits doesn't tell about a function. Maybe Python uses a different name for it s

Re: [Tutor] : unexpected behavior with assignment in __init__

2006-01-25 Thread Orri Ganel
Kent Johnson wrote: variable, it has no effect outside the method; inside a method, self is just a method parameter, nothing more. There is some magic that gives self its value for the call. When __init__() is called the new instance has already been created, you are just initializing it

[Tutor] : unexpected behavior with assignment in __init__

2006-01-24 Thread Orri Ganel
Hello all,     I was just messing around with a suggestion w chun (wescpy at gmail dot com) gave (to make a class that handles time, ie: >>> import myTime >>> c = myTime.myTime(10,30) >>> print c 10:30 >>> d = myTime.myTime(8,45) >>> print c + d 19:15 etc), and I was trying to make it like th

Re: [Tutor] [Re] Fwd: Strings backwards

2006-01-19 Thread Orri Ganel
Victor Bouffier wrote: >I had to do the string-to-list-then-reverse-string-then-back-to-string >process myself before knowing about this marvelous operand. >It works on tuples (all immutable objects) too: > [SNIP] Not all immutable objects, just those that define __getslice__ (basically, those t

Re: [Tutor] Returning multiple values from a script

2006-01-11 Thread Orri Ganel
Hans Dushanthakumar wrote: >Oops answered my own question. Dynamic importing is done using the >__import__ function: > >t = ["test1.py", "test2.py"] #Actually this list is filled in by a >Tkinter Listbox selection. > >for f in t: >testname = f[:-3] >test = __import__("%s"%(testname)) >

Re: [Tutor] Returning multiple values from a script

2006-01-11 Thread Orri Ganel
Hans Dushanthakumar wrote: >Thanks for your reply Kent. > >Is it possible to dynamically import a module? > >The foll snippet of code throws an error "ImportError: No module named >testname" > > >t = ["test1.py", "test2.py"] #Actually this list is filled in by a >Tkinter Listbox selection. > >for

Re: [Tutor] Newb ?

2005-11-17 Thread Orri Ganel
Christian Wyglendowski wrote: >Liam said: > > >>How about - >>print "\n\nWelcome to the Backwards Message Display." >>print >>message = raw_input("\nPlease Enter a Message.") >>msgAsList = [ char for char in message] >> >> > >You could also do: > >msgAsList = list(message) > >list() takes an

Re: [Tutor] What does Python gain by having immutable types?

2005-11-14 Thread Orri Ganel
Hugo González Monteverde wrote: >>Quite often the only answer is "just because". Some features are >>the way they are because that's Guido's pesonal preference. Others >>may disagree with him but it's his language and he gets to pick >>what he thinks is best - the benign dictator syndrome. >>

Re: [Tutor] Converting a String to a Tuple

2005-11-04 Thread Orri Ganel
Carroll, Barry wrote: >Greetings: > >My UDP client is receiving responses from the server, and now I need to >process them. A typical response string looks like this: > >"(0, ''),some data from the test system" > >The tuple represents the error code and message. If the command had failed, >t

Re: [Tutor] : [Slightly OT] Using Python to intercept audio from a program

2005-10-31 Thread Orri Ganel
By the way, if it makes a difference, the program I intend to attempt this with is Rhapsody , a part of the RealPlayer collection of media software. -- Email: singingxduck AT gmail DOT com AIM: singingxduck Programming Python for the fun of it. ___

[Tutor] : [Slightly OT] Using Python to intercept audio from a program

2005-10-31 Thread Orri Ganel
Title: [Tutor]: [Slightly OT] Using Python to intercept audio from a program Hello all, A week or two ago I sent in a few emails regarding using threads in automating conversion between wav's and mp3's using lame.  However, the program I use to generate these wav's, Audacity (a great program,

Re: [Tutor] : Threads?

2005-10-24 Thread Orri Ganel
Not sure what IIUC stands for, but I am, indeed, running windows. XP Home Edition, in fact, with Python 2.4.2 finalOn 10/24/05, Kent Johnson < [EMAIL PROTECTED]> wrote:Hugo González Monteverde wrote:> I have done scripts for decompressing MP3 in the past. I normally follow > a fork() exec() subproc

Re: [Tutor] : Threads?

2005-10-22 Thread Orri Ganel
I knew what he meant, but since most albums have around 12 tracks, 4 tracks per thread gives you 3 threads. In any case, thanks for the catch on the loop. I'll let you know if it makes a difference.On 10/22/05, Kent Johnson <[EMAIL PROTECTED]> wrote: Alan means to use two or three threads *total*.O

Re: [Tutor] : Threads?

2005-10-21 Thread Orri Ganel
I'll try doing 3 or 4 tracks per thread, then. Thanks for the advice.If you keep the thread count down to two or three you might get a noticable improvement but one thread per track, unless you havea lot of separate hard disk spindles to distribute the work willnot help much I suspect.Alan G. -- Em

Re: [Tutor] : Threads?

2005-10-21 Thread Orri Ganel
Kent Johnson wrote: >Orri Ganel wrote: > > >>Hello all, >> >>I've been working on a program for a week or two now that will convert >>all the wav files in a folder to mp3s, filling the id3 tags with the >>correct information as collected from grace

[Tutor] : Threads?

2005-10-21 Thread Orri Ganel
Hello all, I've been working on a program for a week or two now that will convert all the wav files in a folder to mp3s, filling the id3 tags with the correct information as collected from gracenote.com. This part works fine. However, the actual conversion to mp3 takes between 30 and 50 seco

Re: [Tutor] List of class instances

2005-09-20 Thread Orri Ganel
As a side-note, unless you're okay with only being able to access those instance variables through the fields list (ie fields[0], fields[1], fields[2]), you may want to actually name them first. Jan Eden wrote: >Hi, > >Jan Eden wrote on 20.09.2005: > > > >>Hi, >> >>I'd like to form a list of

Re: [Tutor] Aschenputtel problem

2005-09-16 Thread Orri Ganel
Christopher Arndt wrote: >Hi, > >I wonder if there is a shorter form of the following idiom: > >list1 = [] >list2 = [] >for item in original_list: >if condition(item): >list1.append(item) >else: >list2.append(item) > >(optional step:) > >original_list[:] = list1 > > >I call

Re: [Tutor] Parsing os.popen(command) output

2005-09-11 Thread Orri Ganel
Bill Burns wrote: >Kent, > >Thank you for the reply! I knew there had to be a different way to do >it, I didn't like the three lists in there either :-) > >One thing: >I had to change the line > >wRes = float(data[1][1:]) > >it was returning '00,' (zero, zero, comma) instead of '400', so I >change

Re: [Tutor] Importingf a List from Module

2005-08-28 Thread Orri Ganel
On 8/28/05, Tom Strickland <[EMAIL PROTECTED]> wrote: Tom Strickland wrote:>>Here are the modules in question:>> > ##This is the enterData.py module> ##!/usr/bin/python2.4> input = open('/home/tom/Python/Input/SPY2.csv', 'r')> s = input> date =[]> open = []> close = []> hi = [] > lo = []> v

Re: [Tutor] Website Retrieval Program

2005-08-24 Thread Orri Ganel
Daniel Watkins wrote: >I'm currently trying to write a script that will get all the files >necessary for a webpage to display correctly, followed by all the >intra-site pages and such forth, in order to try and retrieve one of the >many sites I have got jumbled up on my webspace. After starting th

Re: [Tutor] Writing to text files

2005-08-22 Thread Orri Ganel
Bob Gailer wrote: >At 08:09 AM 8/22/2005, Byron wrote: > > >>Hi Johan, >> >>It's actually fairly simply and straight forward... Here's how to do >>it: (I haven't officially tested this code for bugs, but I believe it >>is correct.) >> >>file = open("datafile.txt", "r") >> >> > >This is an

Re: [Tutor] Writing to text files

2005-08-22 Thread Orri Ganel
Byron wrote: >Hi Johan, > >It's actually fairly simply and straight forward... Here's how to do >it: (I haven't officially tested this code for bugs, but I believe it >is correct.) > >file = open("datafile.txt", "r") >filedata = file.read() >file.close() > >newLine = "Your new line of data wit

Re: [Tutor] no rsplit

2005-08-21 Thread Orri Ganel
Jonas Melian wrote: >v = "64x43x12" -> '64x43', '12' > >How split it by the las 'x'? > >In 2.4 it could be used rsplit("x",1) > >but i've 2.3.5 > >Is there another way of splitting a string from the end? >___ >Tutor maillist - [EMAIL PROTECTED] >http:

Re: [Tutor] Python in HTML

2005-05-22 Thread Orri Ganel
Thanks to all who helped. It looks like I figured out what the problem was, with the use of mozilla's DOM inspector, js debugger, and JSIDE (a javascript ide) that I downloaded after googling "javascript ide" (it appears to be quite good). In any case, the whole issue was checking whether or

Re: [Tutor] Python in HTML

2005-05-22 Thread Orri Ganel
Kent Johnson wrote: Liam Clarke wrote: Um, man, that's what I hate about Javascript, it fails silently. I've never met a Javascript console... /me ponders Firefox plugin. Firefox has a JavaScript console that can be helpful... Kent Many thanks. I was not aware of this. -- Email: sing

Re: [Tutor] Python in HTML

2005-05-22 Thread Orri Ganel
Alan G wrote: >HI Orri, > > > >>>OK, so what happened? >>> >>> > >You still aren't telling us what happens. Its very hard to find >a fault in a program when you have no idea what the problem is. >The code is very likely doing what you have asked it to do, >so when we read it it will seem t

Re: [Tutor] Python in HTML

2005-05-22 Thread Orri Ganel
EJP wrote: >>Well, like I said, the darkplayer is on an online journal, which means >>that the only output possible is modifying the option strings of songs >>as they are played or something similar. I do know that the random >>number generator works, and the songs played always match the opti

Re: [Tutor] Python in HTML

2005-05-21 Thread Orri Ganel
Alan G wrote: >OK, so what happened? >Did you start just making the copy and playing the songs from the >copy? >Did that work OK? > >Does the random number generation work - I assume you tested that by >just writing out the sequence of numbers first? > >And finally when you use the random numbvers

Re: [Tutor] Python in HTML

2005-05-21 Thread Orri Ganel
Alan G wrote: > The problem lies not on the server but on the client. > JavaScript support is embedded in every popular browser so it just > works, but none of them know about python. Even if they did it would > require the user to have Python installed, which you can't assume. > > It is possible

[Tutor] Python in HTML

2005-05-20 Thread Orri Ganel
Hello all, I've been trying to use javascript for coding something on a webpage, and I've just about given up on understanding the intricacies of why a given script will work now and not in 5 minutes, and why any bit of code longer than 5 lines doesn't behave as documented. Therefore, I thoug

[Tutor] Python Challenge Level 6

2005-05-10 Thread Orri Ganel
Hello all, First and foremost, for those who don't know, www.pythonchallenge.com is a set of python-related riddles. Now, for those who are past level six, any sort of hint would be appreciated. Right now, all I know is what module to use (i think) and that I have to somehow use it on channel.jpg

Re: [Tutor] odd behavior within __init__

2005-04-14 Thread Orri Ganel
On 4/14/05, Rich Krauter <[EMAIL PROTECTED]> wrote: > Maybe you could use a factory. It would allow you to simplify your Node > class, and encapsulate the instantiation behavior you want outside the > class. Thanks for the suggestion; I think that's what I'll do. On 4/14/05, Max Noel <[EMAIL PRO

[Tutor] odd behavior within __init__

2005-04-14 Thread Orri Ganel
Hello all, As part of a project i'm doing (mostly for the fun of it), I have a class which creates a sort of wrapper around any object to make it suitable for use in a custom container. However, if the class receives an already wrapped object, I want it to just return the object (same id and ever

[Tutor] issues with .remove method

2005-03-30 Thread Orri Ganel
Hello all, True to Pierre's suggestion, I have reimplemented LinkedList without embedding a list in it. I also took out the dictionary, on the basis that dictionaries can behave as badly as O(n), and often behave O(log(n)), depending on the hash function they're based on, and the point of a Linke

Re: [Tutor] A Pythonic LinkedList Implementation

2005-03-28 Thread Orri Ganel
I'm not at all sure this is, indeed, helpful *grin*. I was just looking for a project to code, and decided to implement a LinkedList. The how of using it is very simple: in the same way you would use a regular list. Except for a few extra/different methods, the use of LinkedList is very similar

[Tutor] A Pythonic LinkedList Implementation

2005-03-28 Thread Orri Ganel
Hello all, I've been working on making a complete pythonic LinkedList implementation, as per the specifications of Java's LinkedList and Python's list. The full code may be found at http://rafb.net/paste/results/JKhsQn59.html. Once the link expires, please feel free to email me for the code. An

Re: [Tutor] hash()ing a list

2005-03-28 Thread Orri Ganel
Well, what I ended up doing is making it so that Nodes are equal if they have the same 'cargo', but hash based on memory address. If this wasn't the case, I either wouldn't be able to have multiple Nodes with the same 'cargo' in a LinkedList, or I wouldn't be able to sort them properly, among othe

Re: [Tutor] unhashable objects (unrelated to previous topic)

2005-03-27 Thread Orri Ganel
Thanks to Jeff and John Fouhy . . . However, my question now is: can I treat Nodes sometimes the same and sometimes not? I want to treat Nodes whose cargo is the same the same everywhere *except* in a dictionary, because I want the user to be able to use LinkedList in a broader way than sets allow

Re: [Tutor] hash()ing a list

2005-03-27 Thread Orri Ganel
So, any class that has 'rich comparison methods' defined is unhashable? What gives? (See '[Tutor] unhashable objects') On Sun, 27 Mar 2005 12:38:09 -0800 (PST), Danny Yoo <[EMAIL PROTECTED]> wrote: > > > On Sun, 27 Mar 2005, Orri Ganel wrote: > > >

[Tutor] unhashable objects (unrelated to previous topic)

2005-03-27 Thread Orri Ganel
Hello all, I am attempting to implement a LinkedList in Python, and in doing so, have created a Node class which represents the elements of the LinkedList. However, since these Nodes have custom-defined __lt__(), __gt__(), __le__(), __ge__(), __eq__(), and __ne__() methods, they are, for some rea

[Tutor] hash()ing a list

2005-03-27 Thread Orri Ganel
Hello all, While I do not have a pressing need to hash a list, I am curious as to why, if lists are unhashable, there is a __hash__() method in the list class, which also does not work on lists, but results in a 'TypeError: list objects are unhashable'. What's the point of including a __hash__()

Re: [Tutor] Better structure?

2005-02-02 Thread Orri Ganel
Sandip Bhattacharya wrote: for x in string: if x in chars: string[i] = '' I just have a hangover from other languages, but I really wanted to know how Python handles iteration over a variable which is being changed within the loop itself. Is the "for" condition evaluated in

Re: [Tutor] Better structure?

2005-02-02 Thread Orri Ganel
Orri Ganel wrote: Kent Johnson wrote: Jacob S. wrote: Try writing the code to do what lstrip actually does - its much harder. So the library includes the more difficult function and lets you code the easy ones. def lstrip(string,chars=' ') string = list(string) t = 0 for x

Re: [Tutor] Better structure?

2005-02-02 Thread Orri Ganel
Kent Johnson wrote: Jacob S. wrote: Try writing the code to do what lstrip actually does - its much harder. So the library includes the more difficult function and lets you code the easy ones. def lstrip(string,chars=' ') string = list(string) t = 0 for x in string: if x in chars:

Re: [Tutor] How to sum rows and columns of a matrix?

2005-01-31 Thread Orri Ganel
Gregor Lingl wrote: Hi all of you, I'm representing a 4x4 matrix as a 16-element list, e.g. m=range(16) first 4 elements first row, second four elements second row etc. I want to sum rows and columns like i-th row: sum(m[4*i:4*i+4]) and ith column: sum(m[i::4]) This seems to be slow because of the

Re: [Tutor] carriage return on windows

2005-01-29 Thread Orri Ganel
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 *o

Re: Fwd: [Tutor] Control flow

2005-01-29 Thread Orri Ganel
Kent Johnson wrote: Bob Gailer wrote: At 04:43 AM 1/29/2005, Liam Clarke wrote: < erk, to the list, to the List!> if ( bad_weather =='y' ): # ask user only if weather is bad. b = input ( "Weather is really bad, still go out to jog?[y/n]" ) if b == 'y': go_jogging() Anyone else notice

Re: [Tutor] Control flow

2005-01-28 Thread Orri Ganel
Gilbert Tsang wrote: Hi there, I have this logic that I cannot wrap my mind it: def go_jogging(): # go out and jog return if ( bad_weather =='y' ): # ask user only if weather is bad. b = input ( "Weather is really bad, still go out to jog?[y/n]" ) if b == 'y': go_jogging() e

Re: [Tutor] Control flow

2005-01-28 Thread Orri Ganel
Gilbert Tsang wrote: Hi there, I have this logic that I cannot wrap my mind it: def go_jogging(): # go out and jog return if ( bad_weather =='y' ): # ask user only if weather is bad. b = input ( "Weather is really bad, still go out to jog?[y/n]" ) if b == 'y': go_jogging() e

Re: [Tutor] on the way to find pi

2005-01-23 Thread Orri Ganel
Ali Polatel wrote: dear friends , I found a code which calculates pi with an interesting algorithm the programme code is below: from sys import stdout def f((q,r,t,k)):     n = (3*q+r) / t     if (4*q+r) / t == n:     return (10*q,10*(r-n*t),t,k,n)     else:     return (q*k, q*

Re: [Tutor] flattening a list

2005-01-22 Thread Orri Ganel
Jacob S. wrote: Ahh, my pitiful form of flattening a list that cheats... def flatten(li): li = str(li) li = li.replace("[","") li = li.replace("]","") li = li.replace("(","") li = li.replace(")","") li = "[%s]"%li return eval(li) It works! It's probably just a bit slower

Re: [Tutor] Print record x in a file

2005-01-22 Thread Orri Ganel
Jacob S. wrote: This will get a random record I hope you do not think the comments are patronising but you did say you are new so I did not want to give naked code. import random #the above gives the program the ability to get a #pseudo random number file = open('test.rantxt') listcontents = file.r

Re: [Tutor] read line x from a file

2005-01-21 Thread Orri Ganel
Jay Loden wrote: One simple solution is to do: fle = open(file) contents = file.readlines() file.close() print contents[x] #or store this in a variable, whatever -Jay On Friday 21 January 2005 11:22, J. M. Strother wrote: I have a text file containing 336 records. I can read

Re: [Tutor] read line x from a file

2005-01-21 Thread Orri Ganel
J. M. Strother wrote: I have  a text file containing 336 records. I can read and print out the whole file without any problem. What I want to do is read and print out one record only (chosen at random). So I need to get to record x, select it, and then print it (or store it in a variable)

Re: [Tutor] Unexpected result from decimal

2005-01-19 Thread Orri Ganel
Jacob S. wrote: Hi all,    I'm having a problem that is ticking me off. (to put it lightly) Why does decimal do this --  I thought that getcontext().prec was number of decimal places? import decimal decimal.getcontext().prec = 2 a = decimal.Decimal

Re: [Tutor] RE:

2005-01-18 Thread Orri Ganel
Title: RE: Gopinath V, ASDC Chennai wrote: On Wed, 12 Jan 2005, Orri Ganel wrote: >  >>> stuff = [[0,'sdfsd','wrtew'], [1, 'rht','erterg']] >  >>> stuff > [[0, 'sdfsd', 'wrte

Re: [Tutor] RE:

2005-01-18 Thread Orri Ganel
Title: RE: Gopinath V, ASDC Chennai wrote: On Wed, 12 Jan 2005, Orri Ganel wrote: >  >>> stuff = [[0,'sdfsd','wrtew'], [1, 'rht','erterg']] >  >>> stuff > [[0, 'sdfsd', 'wrte

[Tutor] Getting access to the speakers

2005-01-17 Thread Orri Ganel
Hello all, I've googled the topic a bit, and can't seem to find any relevant information. Does anyone know how to gain access to the speakers and, for example, tell when they are playing a sound and when they are not? I would think it's something with sockets, but I don't know how to go about

[Tutor] Setting the focus to a window

2005-01-16 Thread Orri Ganel
Hello all, As part of a project I'm working on (see archive of previous emails from me in the past 2 days or so), I need to change the focus from the current window to another window (from Windows Media Player to Audacity so that the simulated keypress will have an effect). I have googled and

Re: [Tutor] Posting a large amount of code?

2005-01-16 Thread Orri Ganel
Bill Burns wrote: I accidentally sent my reply to Kent only. So I'm forwarding it to the list. Bill -- Forwarded Message -- Subject: Re: [Tutor] Posting a large amount of code? Date: Sunday 16 January 2005 10:14 am From: Bill Burns <[EMAIL PROTECTED]> To: Kent Johnson <[EM

Re: Sending a command to a program using os.system (was [Tutor]: Using os.popen*() and os.spawn*() to interact with a DOS box)

2005-01-16 Thread Orri Ganel
hints. The Snack Sound Toolkit in particular. http://www.speech.kth.se/snack/ OTOH if what you want is some kind of macro system for Audacity then this won't help. Kent Orri Ganel wrote: I did some googling, and found this in the archives of this mailing list: import os os.system(

Re: Sending a command to a program using os.system (was [Tutor]: Using os.popen*() and os.spawn*() to interact with a DOS box)

2005-01-15 Thread Orri Ganel
Orri Ganel wrote: I did some googling, and found this in the archives of this mailing list: import os os.system('c:\\abaqus\\5.8-14\\abaqus.exe post') , where post was a command, *not* a file.  Now, I tried something similar, since essentially what I wish to be able to

Sending a command to a program using os.system (was [Tutor]: Using os.popen*() and os.spawn*() to interact with a DOS box)

2005-01-15 Thread Orri Ganel
I did some googling, and found this in the archives of this mailing list: import os os.system('c:\\abaqus\\5.8-14\\abaqus.exe post') , where post was a command, *not* a file.  Now, I tried something similar, since essentially what I wish to be able to do is have Audacity think I typed the 'R

Re: [Tutor] Using os.popen*() and os.spawn*() to interact with a dos-box

2005-01-15 Thread Orri Ganel
Alan Gauld wrote: Well, ultimately, what I want to be able to do is open Audacity (http://audacity.sourceforge.net/) at a predetermined time and have it begin recording wave mix out (the default i have it set to anyway), and then have it stop agai

Re: [Tutor] Using os.popen*() and os.spawn*() to interact with a dos-box

2005-01-15 Thread Orri Ganel
Alan Gauld wrote: I'm trying to use Python to start the dos-box ("cmd.exe") and be able to call commands on it and receive output from it. The Command window is just a terminal, there is no output to be had other than an exit code when it closes.

[Tutor] Using os.popen*() and os.spawn*() to interact with a dos-box

2005-01-14 Thread Orri Ganel
Hello all, I'm trying to use Python to start the dos-box ("cmd.exe") and be able to call commands on it and receive output from it. However, none of the documentation for popen and spawn cover this . . . Any help would be appreciated. Thanks in advance, Orri -- Email: singingxduck AT gmail DOT

Re: [Tutor] flattening a list

2005-01-14 Thread Orri Ganel
One final note to wrap things up. I posted a slightly cleaner version of my code on the Python Cookbook, with a reference to the solutions of Gonçalo and Danny via the tutor archives here: http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/363051 -- Email: singingxduck AT gmail DOT com AIM

Re: [Tutor] what's a concise way to print the first elements in a nested list

2005-01-12 Thread Orri Ganel
Danny Yoo wrote: On Wed, 12 Jan 2005, Orri Ganel wrote: >>> stuff = [[0,'sdfsd','wrtew'], [1, 'rht','erterg']] >>> stuff [[0, 'sdfsd', 'wrtew'], [1, 'rht', 'erterg']] >>&

Re: [Tutor] what's a concise way to print the first elements in a nested list

2005-01-12 Thread Orri Ganel
Vincent Wan wrote: If I have a list stuff = [[0,sdfsd,wrtew], [1, rht,erterg]] whats the most concise way to print the first elements: [0, 1] if triedprint stuff[:][0] but that just prints the whole list. Vincent

Re: [Tutor] Matching multiple regular expressions

2005-01-12 Thread Orri Ganel
Kent Johnson wrote: Just join the individual strings together with | to make a single regex, then search each line for a match: >>> import re >>> lista = ['hello','goodbye','bubblegum'] >>> regex = re.compile('|'.join(lista)) >>> lines = '''line1: blah blah aldkfslfjlajf hello ... line2: bla

Re: [Tutor] flattening a list

2005-01-12 Thread Orri Ganel
Bill Kranec wrote: Hello, I have a list of lists, for example [ [1,2] , [3,4] ], and I would like to pass all the elements of that list as arguments to a function (for example the intersection of all list elements). Is there a command in regular Python to do this? I would like to avoid the ha

Re: [Tutor] Array pointers

2005-01-05 Thread Orri Ganel
I don't know about a large calculation time, but this seems to work: >>> def rightshift(a): ia = a[:] for i in range(len(ia)-1,0,-1): if ia[i-1] == 1 and ia[i]!=1: ia[i]=1 ia[i-1]=0 return ia

Re: [Tutor] Breaking down integers?

2005-01-03 Thread Orri Ganel
On Mon, 03 Jan 2005 17:41:49 -0500, Brian van den Broek <[EMAIL PROTECTED]> wrote: > .>>> an_int_as_string_list = list(an_int_as_string) > .>>> print an_int_as_string_list > ['4', '2'] *Smacks head with palm* Of course, you're right . . . no need to go into ' '.join(str(x)).split() . . . Python's

Re: [Tutor] Breaking down integers?

2005-01-03 Thread Orri Ganel
On Mon, 3 Jan 2005 17:17:36 -0500, kilovh <[EMAIL PROTECTED]> wrote: > > I would like to be able to take an integer, break it down into individual > items in a list, and then put them back together. I know how to do this last > part thanks to Orri Ganel and Guillermo Fernand

Re: [Tutor] Re: Soem list operation questions?

2004-12-28 Thread Orri Ganel
Karl, The ''.join() method was the first one suggested. Roel then suggested a math-based method, which I attempted to improve upon. -- Email: singingxduck AT gmail DOT com AIM: singingxduck Programming Python for the fun of it. ___ Tutor maillist - Tu

Re: [Tutor] Re: Soem list operation questions?

2004-12-28 Thread Orri Ganel
Though, of course, by modifying your way (using str() ), it will still work: >>> def listtoint(digits): result = 0 for digit in digits: result *= (10**len(str(digit))) ## just multiply it by 10 result += digit ## to the power of the number of digits return result >>> l

Re: [Tutor] Re: Soem list operation questions?

2004-12-28 Thread Orri Ganel
Yes, but your way only works when the numbers in the list are single digit: >>> def listtoint(digits): result = 0 for digit in digits: result *= 10 result += digit return result >>> listtoint([1,2,3,4]) 1234 >>> listtoint([11,22,33,44]) 13574 -- Email: singingxduck A

Re: [Tutor] Soem list operation questions?

2004-12-27 Thread Orri Ganel
Hello kilovh. > 1. Is there any easy way to compeltely reverse a list so that the last index > becomes the first, etc.? Why, yes. It's the 'reverse' method of lists. ie: >>> li = [1,2,3,4] >>> li.reverse() >>> li [4, 3, 2, 1] >>> > 2. Is there any way to take seperate integers in a list a

Re: [Tutor] O.T.

2004-12-27 Thread Orri Ganel
Hello, 15, taught myself Python last year, attend high school in Maryland (USA), born in Israel, moved to Texas at 3, and to MD in 3rd grade . . . Currently learning Java in school, so those are the only languages I'm (semi)comfortable with. Orri -- Email: singingxduck AT gmail DOT com AIM: sin

Re: [Tutor] Is there an easy way to conduct binary numbers?

2004-12-23 Thread Orri Ganel
On Thu, 23 Dec 2004 20:42:50 +0800, Juan Shen <[EMAIL PROTECTED]> wrote: > I have found there are easy functions and options to do basic octal and > hexadecimal number operation. > > oct(...) > oct(number) -> string > > Return the octal representation of an integer or long integer. > > hex(...)

Re: [Tutor] silly question

2004-12-22 Thread Orri Ganel
On Wed, 22 Dec 2004 17:52:53 -0700, Jason Child <[EMAIL PROTECTED]> wrote: > Ok, I guess my question (now) is: > > how do I change global variables within a function: > > ## > VAR = "TEST" > > def m(): > VAR="no test" > ## > >

Re: [Tutor] Leading zero for hex numbers

2004-12-15 Thread Orri Ganel
On Wed, 15 Dec 2004 20:40:40 -0500, R. Alan Monroe <[EMAIL PROTECTED]> wrote: > > print "0x%0X" % 12345 > > > displays > > 0x3039 > > > instead of 0x03039 > > > >>> "%05x" % (12345,) > '03039' > > >>> "0x%05x" % (12345,) > '0x03039' > > ___ > Tutor

  1   2   >