Re: [Tutor] Percentage

2005-11-07 Thread Steve Nelson
On 07 Nov 2005 11:50:05 -0200, Jorge Godoy <[EMAIL PROTECTED]> wrote: > Johan Geldenhuys <[EMAIL PROTECTED]> writes: > > > What is the syntax if I want to work out what percentage 42 is out of 250? > > If you want it as a factor to multiply / divide by something: > > perc = 42/250 Don't you need t

[Tutor] Iterate over letters in a word

2006-03-14 Thread Steve Nelson
Hello, I'm trying to work on some programs to help me understand ciphers and ultimately cryptography. I've understood so far, that a simple form of bit-level cryptography is to split the original message into chunks the same length as a 'key' and then do an xor. I'm trying to keep this really si

Re: [Tutor] Iterate over letters in a word

2006-03-14 Thread Steve Nelson
On 3/14/06, Danny Yoo <[EMAIL PROTECTED]> wrote: > The idea is to unpack four single characters as a single 4-byte integer. That's really useful, thanks, as I was planning to iterate over each letter and call ord() > This kind of transformation is reversable: Highly useful. Thanks very much in

Re: [Tutor] Iterate over letters in a word

2006-03-14 Thread Steve Nelson
On 3/14/06, Matthew Webber <[EMAIL PROTECTED]> wrote: > As a side note, remember that that xor-ing a key with a message is trivial > to break (it's just a variation on the Vigenere cipher first published in > 1568). So don't use if for any real applications. Yes - at the moment this is just a way

Re: [Tutor] Iterate over letters in a word

2006-03-14 Thread Steve Nelson
On 3/14/06, Steve Nelson <[EMAIL PROTECTED]> wrote: > On 3/14/06, Danny Yoo <[EMAIL PROTECTED]> wrote: > > > The idea is to unpack four single characters as a single 4-byte integer. > > That's really useful, thanks, as I was planning to iterate over e

[Tutor] Splitting a string into n-sized bytes

2006-03-14 Thread Steve Nelson
Hello all, Further to my previous puzzling, I've been working out the best way to chop a string up into n-sized words: I'm aware that I can use a slice of the string, with, eg, myWord[0:4]. I am also aware that I can do blob = myWord.pop(0) to take (and remove) the first character. I can botch

Re: [Tutor] Splitting a string into n-sized bytes

2006-03-14 Thread Steve Nelson
On 3/14/06, Adam <[EMAIL PROTECTED]> wrote: > Hopefully that should point you in the right direction to do n-sized > words as well. Indeed - as I now have a function: def nsplit(s, n): return [s[i:i+n] for i in range(0, len(s), n)] Incidentally I am currently going with: def nsplit(s, n):

[Tutor] Alternative to nested loops

2006-03-19 Thread Steve Nelson
Hi All, I had a feeling I could do this: >>> foo [[1, 2, 3], [1, 2, 3], [1, 2, 3]] >>> for c in foo: ... for b in c: ... print b ... 1 2 3 1 2 3 1 2 3 Using a list comprehension, as it seemed to me like I was saying: b for c in foo, but I can't see how to do this. Ultimately I w

Re: [Tutor] Alternative to nested loops

2006-03-19 Thread Steve Nelson
On 3/19/06, Karl Pflästerer <[EMAIL PROTECTED]> wrote: >>> reduce(lambda s, L: s + sum(L), foo, 0) Ah ok - well that looks pretty cryptic to me, as I've never used either lambda or reduce(). However, this looks to be a 'functional' way of doing what I was doing procedurally, which is, I suppose,

Re: [Tutor] Alternative to nested loops

2006-03-19 Thread Steve Nelson
On 3/19/06, John Fouhy <[EMAIL PROTECTED]> wrote: > What you're doing is called "flattening" a list. You can do it with a > list comprehension: > > >>> foo = [[1,2,3], [4,5,6], [7,8,9]] > >>> [x for y in foo for x in y] > [1, 2, 3, 4, 5, 6, 7, 8, 9] Ah yes, that was the sort of thing I was think

Re: [Tutor] Alternative to nested loops

2006-03-19 Thread Steve Nelson
On 3/19/06, Alan Gauld <[EMAIL PROTECTED]> wrote: > > interesting. I've never done any functional programming at all, so it > > all seems a little foreign! > > > > Can you recommend another gentle introduction? > > Try the functional programming topic in the Advanced section of my tutor. > It cov

Re: [Tutor] newbie exercises

2006-03-27 Thread Steve Nelson
On 3/27/06, josip <[EMAIL PROTECTED]> wrote: > Can someone give me exercises to do with loops, maybe functions to? How about a program that produces truth tables for the basic gates? AND, NAND, NOT, OR, XOR? You could write a function for each gate, and one to produce a truth table. S. __

Re: [Tutor] newbie exercises

2006-03-29 Thread Steve Nelson
On 3/29/06, Keo Sophon <[EMAIL PROTECTED]> wrote: > Is it bitwise operator? Could you give one example? >>> for a in range(2): ... for b in range(2): ... print a, b, a&b ... 0 0 0 0 1 0 1 0 0 1 1 1 > Sophon S. ___ Tutor maillist - Tu

Re: [Tutor] How does it function

2006-03-29 Thread Steve Nelson
On 3/29/06, Kaushal Shriyan <[EMAIL PROTECTED]> wrote: > Hi ALL > > Just wanted to know the detailed explanation about the below statement > > if __name__ == "__main__": Simple answer - any python program you write is effectively a 'module'. Modules have an attribute __name__. If you've imported

Re: [Tutor] How does it function

2006-03-30 Thread Steve Nelson
On 3/30/06, Terry Carroll <[EMAIL PROTECTED]> wrote: > On Wed, 29 Mar 2006, Steve Nelson wrote: > > > Simple answer - any python program you write is effectively a > > 'module'. Modules have an attribute __name__. If you've imported the > > module fr

[Tutor] Inverted Index Algorithm

2006-03-31 Thread Steve Nelson
Hello All, I've been reading about "Inverted Indexing" - I'd like to try to write something in Python that illustrates the concpet, as I've got to give a presentation about it. Where would be a good place to start? S. ___ Tutor maillist - Tutor@pytho

Re: [Tutor] Inverted Index Algorithm

2006-03-31 Thread Steve Nelson
On 3/31/06, Kent Johnson <[EMAIL PROTECTED]> wrote: > Steve Nelson wrote: > > Do you need help getting started with Python or with inverted indexing > in particular? Sorry - I should have been clearer. I'm reasonably confident in Python, and if I get stuck with that side

Re: [Tutor] Hi

2006-04-04 Thread Steve Nelson
On 4/4/06, Kaushal Shriyan <[EMAIL PROTECTED]> wrote: > Hi ALL > > A simple query is that the python mailing List is python powered > > What does "python powered" means The list, and many like it, use a piece of software called Mailman, which is written in Python. A few years back, the tool of ch

Re: [Tutor] Python video?

2006-04-13 Thread Steve Nelson
On 4/13/06, Danny Yoo <[EMAIL PROTECTED]> wrote: > > > On Wed, 12 Apr 2006, Hoffmann wrote: > > > I read this week on this forum about a kind of Python video in its > > website. Which view is that, and where could I find it? I search in > > Python website, but I didn't find it. Is it a 'demo' of th

Re: [Tutor] checking diagonals on a chessboard

2006-04-13 Thread Steve Nelson
On 4/13/06, Matthew Singletary <[EMAIL PROTECTED]> wrote: > I'm NOT looking for any answers, just some tips to an _elegant_ method to > solve this. My tutor/mentor and I wrote a chess program a while back - diaganols were the hardest bit to get working! Essentially diagonals are treated as thoug

[Tutor] functions in Python

2006-04-17 Thread Steve Nelson
Sorry - including list. On 4/17/06, Payal Rathod <[EMAIL PROTECTED]> wrote: > what is the difference between, > > def func(): > > > and > > def func(x): > When you define a function, you are writing a block of code which you can ask to perform a task. The task may be si

Re: [Tutor] Books

2006-05-03 Thread Steve Nelson
On 5/3/06, John Connors <[EMAIL PROTECTED]> wrote: > G'day, > > I know this is a difficult question to answer because it's probably more a > matter of personal taste than anything else. It is also a VFAQ. Check the archives - I'm not aware of any radical new books that would render the most recen

[Tutor] Beer Bottles

2006-07-06 Thread Steve Nelson
A bunch of my friends and I have been chatting about "99 bottles of beer" - and how to make the shortest code to do it. I have: for i in range(100,0,-1): print "%s bottles of beer on the wall, %s bottles of beer\nTake on down, pass it around.."%(i,i) print "Go to the store, buy some more" I'm

[Tutor] Test

2006-07-06 Thread Steve Nelson
I got a bounce... but have been on this list for months... S. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor

[Tutor] Functional Programming

2006-07-06 Thread Steve Nelson
Hi All, I've just today starting thinking more about programming in a more functional style, and came across the following article which I thought was really good: http://www.amk.ca/python/writing/functional I know there's a section in Alan's tutorial on FP too, but can anyone else recommend som

[Tutor] Python on AIX

2006-07-12 Thread Steve Nelson
Hello all, Just started a new job - most of the machines I am administering are AIX, and don't have Python at all. What is going to me the most pain-free, scaleable and supportable way of getting Python onto these machines? I need to take this request to change advisory board. Also, I could fin

Re: [Tutor] Python on AIX

2006-07-12 Thread Steve Nelson
On 7/12/06, Kent Johnson <[EMAIL PROTECTED]> wrote: > According to this page Python binaries for AIX are available. If you > click through the links, the versions actually available are more recent > than those listed on the first page. > http://www.python.org/download/other/ Thanks - that's perf

[Tutor] Regular Expression Misunderstanding

2006-07-14 Thread Steve Nelson
Hello, I am reading the "Regular Expression HOWTO" at http://www.amk.ca/python/howto/regex/ I am at the bit where "greediness" is discussed with respect to metacharacters enabling repetition of sections of a RE. I understand the concept. The author gives a step by step example of how the matchi

Re: [Tutor] Regular Expression Misunderstanding

2006-07-14 Thread Steve Nelson
On 7/14/06, John Fouhy <[EMAIL PROTECTED]> wrote: > It doesn't have to match the _whole_ string. Ah right - yes, so it doesn't say that it has to end with a b - as per your comment about ending with $. > If you look at the match object returned, you should se that the match > starts at position

Re: [Tutor] Regular Expression Misunderstanding

2006-07-14 Thread Steve Nelson
On 7/14/06, John Fouhy <[EMAIL PROTECTED]> wrote: > >>> m = re.match(...) > >>> dir(m) > > It will tell you what attributes the match object has. Useful - thank you. I am now confuse on this: I have a file full of lines beginning with the letter "b". I want a RE that will return the whole line

Re: [Tutor] Regular Expression Misunderstanding

2006-07-14 Thread Steve Nelson
On 7/14/06, Kent Johnson <[EMAIL PROTECTED]> wrote: > But for this particular application you might as well use > line.startswith('b') instead of a regex. Ah yes, that makes sense. Incidentally continuing my reading of the HOWTO I have sat and puzzled for about 30 mins on the difference the MULT

[Tutor] Comparing times

2006-07-18 Thread Steve Nelson
Hello there, I need to be able to compare time on a process tree with system time, and take action accordingly. Here's how I get the time on the process tree: >>> for line in os.popen("ps -ef", "r"): ... if "telnet" in line: ... print line.split()[4] ... 11:00:25 11:01:31 10:01:

Re: [Tutor] Comparing times

2006-07-19 Thread Steve Nelson
On 7/18/06, John Fouhy <[EMAIL PROTECTED]> wrote: > On 18/07/06, Steve Nelson <[EMAIL PROTECTED]> wrote: > > What I want to do is establish if the time of the process is *later* > > than the system date. For example, we might have a process with a > > time of 11:

[Tutor] Filesystem Usage

2006-09-21 Thread Steve Nelson
Hello chums, How can I go about getting info similar to that which the UNIX df command provides - of filesystem usage and inode usage? I could just shell out and run a df command, but I would rather use python bindings. What's the recommendation? S. _

Re: [Tutor] Filesystem Usage

2006-09-22 Thread Steve Nelson
On 9/22/06, wesley chun <[EMAIL PROTECTED]> wrote: > this sounds like it will require some work to implement 'df' in > Python Mmm... although I have discovered a debian package called pydf whose source made interesting reading. > i'd use the one of > the {os,popen2}.popen*() functions or the sub

[Tutor] Extract from Word Doc

2006-11-28 Thread Steve Nelson
Hello, Is there a way to pull "strings" out of a word document? Not unlike the way the UNIX command "strings" does? I want this to be OS-portable, so shelling out is not an option. I tried opening the word doc and then looking at it using the object's methods, but it is all binary info, and can

[Tutor] Getting GID info

2007-01-19 Thread Steve Nelson
Hello all, I want to produce stats on file ownership. I am aware that I can use stat to obtain a file statistics tuple, and with the pwd method I can convert the UID to username. However, is there a similar method that will tell me that GID 1 == "staff"? S. _

Re: [Tutor] Getting GID info

2007-01-19 Thread Steve Nelson
On 1/19/07, Steve Nelson <[EMAIL PROTECTED]> wrote: > Hello all, > > I want to produce stats on file ownership. I am aware that I can use > stat to obtain a file statistics tuple, and with the pwd method I can > convert the UID to username. However, is there a similar metho

Re: [Tutor] Filesystem Usage

2007-01-19 Thread Steve Nelson
On 9/22/06, Steve Nelson <[EMAIL PROTECTED]> wrote: > In the end I just did: > > def fsUsage(dir): > """Returns the % usage of a given filesystem""" > stat = os.statvfs(dir) > from statvfs import F_BLOCKS, F_BFREE > total = stat[F

Re: [Tutor] Filesystem Usage

2007-01-19 Thread Steve Nelson
On 1/19/07, Kent Johnson <[EMAIL PROTECTED]> wrote: > The attribute access uses . notation and an attribute name. You can do > stat.f_blocks and gstat.gr_gid. Python takes care of looking up the > actual attribute value. Excellent - thank you. > I suggest you use the attribute form for both, it

[Tutor] MD5 Digest for files

2007-01-19 Thread Steve Nelson
Hello, I want to create a dictionary of files and md5sums for a given directory. It seems, however, that md5 works with strings or read-only buffers, and can't be passed a file. What I want to do is something like: for f is os.listdir("."): d[f] = someFunctionThatReturnsMD5Sum(f) Has this wh

[Tutor] Better printing?

2007-01-22 Thread Steve Nelson
Hello, See below a program that will go through a directory and for each file print user, group, size and md5sum. A few questions: 1) It seems to fall over if I pass "." as a directory - how can I stop this? 2) When I wrote the methods I decided to do isafile() checks there, but subsequently rea

[Tutor] Variable Swap

2007-01-29 Thread Steve Nelson
Hello, I understand the use of xor to do a variable swap without a temporary variable: >>> x=2 >>> y=3 >>> y=x^y >>> x=x^y >>> y=x^y >>> x 3 >>> y 2 However, why do I see this? >>> y=x^y >>> y 1 S. ___ Tutor maillist - Tutor@python.org http://mail

Re: [Tutor] Variable Swap

2007-01-30 Thread Steve Nelson
On 1/29/07, Kent Johnson <[EMAIL PROTECTED]> wrote: > Because 2 ^ 3 == 1, right? Are you sure you understand what xor does? It > is a bitwise exclusive or: Yes... at a binary level, it returns true if either input is true, but not both: A B Q 0 0 0 0 1 1 1 0 1 1 1 0 Thus it has the effect of swa

[Tutor] VOT - Similar list for Ruby?

2007-02-01 Thread Steve Nelson
Hello all, I may be about to switch jobs to an environment in which the main utility language is Ruby. I've found this group to be brilliant in the last few years, and wondered if anyone on the list is also a Ruby user, and could recommend a similarly helpful, patient and informative list? Thank

[Tutor] MapReduce

2007-02-05 Thread Steve Nelson
Hello, I have to give a presentation this week on how the MapReduce (of Google and Hadoop fame) algorithm works. I understand how map() works, and how reduce() works, and having read the google papers, I have an idea of their implementation (which I must say takes certain liberties with FP-derive

Re: [Tutor] MapReduce

2007-02-05 Thread Steve Nelson
On 2/5/07, Steve Nelson <[EMAIL PROTECTED]> wrote: > What I want to do is now "group" these urls so that repeated urls have > as their "partner" a lsit of indexes. To take a test example of the > method I have in mind: > > def testGrouper(self): >

Re: [Tutor] MapReduce

2007-02-06 Thread Steve Nelson
On 2/5/07, Kent Johnson <[EMAIL PROTECTED]> wrote: > You can also do this operation easily with dicts (not tested!): Thank you - code now complete and tests passing. Would appreciate comments / criticisms. I did wonder if I should create a UrlAnalyser Class rather than have hanging methods: #!/

[Tutor] Python for Sysadmins

2007-02-13 Thread Steve Nelson
Hello chaps, So further to the MapReduce question, it helped greatly, and I got the job, so I'll now be programming Ruby for a living... Before I leave my present job, I've been asked to put together a day's course on Python for Sysadmins. This is mainly to enable them to maintain my code, and g