Re: [Tutor] FW: wierd replace problem

2010-09-15 Thread Roelof Wobben




> Date: Tue, 14 Sep 2010 22:15:40 +0100
> From: wpr...@gmail.com
> To: tutor@python.org
> Subject: Re: [Tutor] FW: wierd replace problem
>
>
>
> On 14 September 2010 21:10, Roelof Wobben
>> wrote:
> I understand it but I try to understand why in a file there is this
> 'word python makes a "'word.
>
> Python doesn't change what it reads from the file. However, depending
> on how you ask Python to tell you what it's read (or what the contents
> of a string variable is), it might display it quoted, and/or include
> escape charaters, or not as the case may be. If what you've read from
> the file contains quotes, then obviously you need to be careful to not
> mistake Python's quoting of the value of a string as being *part* of
> that string. Neither must you mistake the escape character (if
> applicable) from being actually part of the string.
>
> For example, consider the following exchange in the Python shell
> (please try all of this yourself and experiment):
>
 s = 'blah'
 s
> 'blah'
 print s
> blah

>
> I assign the value of 'blah' to the string s. So far simple enough.
> Obviosuly the quotes used int the assignment of the string does not
> form part of the string itself. Their utility is only to delineate to
> Python the start of the string, and the end of the string.
>
> In the next line I ask Python to evaluate the expression s, which it
> duly reporst as 'blah'. Again, it's using normal Python convention to
> format the data as a string, because that's what s is, a string
> object. But the quotes are formatting, they're not really part of the
> string.
>
> In the next line I ask Python to print s. Now, the true content of s
> is printed as it is, and hence you can see that the quotes are not part
> of the string.
>
> Now consider the following exchange in the Python shell where I open a
> file and write some text to it to prove this point:
 f = open('test.txt', 'w+')
 f.write('blah')
 f.close()
 import os
 os.system('notepad test.txt')
>
> The last line above opens the text file test.txt in Notepad so you can
> see the contents. As you can see, no quotes or anything else. Now,
> while open, suppose we put a single quote in the file, so it reads:
> 'blah
> ...and suppose we then save it and exit notepad so you're back in the
> Python shell. Then we do:
>
 f=open('test.txt','r+')
 s=f.read()
 f.close()
 s
> "'blah"
>
> Now I've read the contents of the file back into a string variable s,
> and asked Python to evaluate (output) this string object.
>
> Notice, Python is now formatting the string with *doube* quotes
> (previously it defaulted to single quotes) to avoid having to escape
> the single quote that forms part of the string. If Python had used
> single quotes instead, then there would've been an ambiguity with the
> single quote that's part of the string and so it would've had to escape
> that too. So consequently it formats the string with double quotes,
> which is valid Python syntax and avoids the backslash. (Stating the
> obvious, strings can be quoted with double or single quotes.) As
> before, the double quotes, as with the single quotes earlier, are not
> part of the string. They are merely formatting since Python is being
> asked to display a string and hence it must indicate the start and end
> of the string with suitable quote characters.
>
> Now, as before do:
>
 print s
> 'blah
>
> As before, with print you see the contents of the string as it is (and
> as indeed it is also in the file that you saved). Just the single quote
> you added at the front of Blah. No double or single quotes or anything
> else.
>
> Now finally, let's try something a bit more elaborate. Do again:
>
 os.system('notepad test.txt')
>
> Then put into the file the following 2 lines of text (notice the file
> now contains 2 lines, and both single and double quotes...):
> +++"+++This line is double quoted in the file and the quotes have +
> symbols around them.+++"+++
> ---'---This line is single quoted in the file and the quotes have -
> symbols around them.---'---
>
> Save it, exit Notepad, then do:
 f=open('test.txt', 'r+')
 s=f.read()
 f.close()
 s
> '+++"+++This line is double quoted in the file and the quotes have +
> symbols around them.+++"+++\n---\'---This line is single quoted in the
> file and the quotes have - symbols around them.---\'---\n'
 print s
> +++"+++This line is double quoted in the file and the quotes have +
> symbols around them.+++"+++
> ---'---This line is single quoted in the file and the quotes have -
> symbols around them.---'---
>
> Notice we read both lines in the file into one single string. See how
> Python formats that as a string object, and escapes not only the single
> quotes but also the line break characters (\n). See also when Python
> is asked to "print" the string, you can see the escape characters
> really there. See what's happened? Do you understand why?
>
> W

[Tutor] what happened to the cards module

2010-09-15 Thread jsoares
I downloaded Python 2.6.6 for windows but I can't access the "Cards" module for 
playing card games.

Did it get renamed? If so, how can I find it?

Thanks.

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


Re: [Tutor] list dll functions ?

2010-09-15 Thread patrice laporte
Dependdencyy walker is a good tool, but as you have seen it doesn't give you
function's signature. If you explore a MS dll, you should to have a look at
MSDN and read about the function description.

A bit out of subject : There is no way to find the function's signature only
from exploring the binary file (I never found one at least). Following
article explain the MS PE (Portable Executable, no elf format in Windows),
but it doesn't explain more about signature. this is why you need headers
and lib file to link a w32 app.

http://msdn.microsoft.com/en-us/library/ms809762.aspx
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] what happened to the cards module

2010-09-15 Thread Evert Rol
> I downloaded Python 2.6.6 for windows but I can't access the "Cards" module 
> for playing card games.
> 
> Did it get renamed? If so, how can I find it?

I don't think there's a Cards module in the standard library. At least, I've 
never seen it, nor can I find any mention about it on the python documentation 
page.

Probably this is a module you installed yourself later on, and is now only 
accessible for your previous Python version? You would have to reinstall it for 
Python 2.6.
How did you previously use Cards? What Python version.

Btw, I don't know what your upgrade path is, but can't you go to Python 2.7 
directly?

  Evert

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


Re: [Tutor] how best to implement paginated data in CLI

2010-09-15 Thread Alan Gauld


"Rance Hall"  wrote


In reviewing the app I'm hoping to replace I found the size of the
client list is under 100 records.

Given this new information, do you still think that db cursors is 
the way to go?


Using the cursor is a more scaleable solution but if you are sure you 
only
ever have 100 or so rows then I agree that sing a local client side 
windowing

scheme may be as effective.

Using the cursor should not be onerous however, it should look 
something

like:

configure cursor page size
for each page in cursor
 display screen
 process data

The only downside is, as you say that you are now dipping into the 
cursor
for every 10 records which would be a lot of network traffic. I'd 
expect the

"induistrial" solution to this to be something like

set cursor to 100 records (or even 1000 depending on size)
for each page in cursor
for each screen in page
 display screen
 process data

So if you are sure you will only ever have about 100 records you can
omit the cursor paging.


--
Alan Gauld
Author of the Learn to Program web site
http://www.alan-g.me.uk/


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


Re: [Tutor] list dll functions?

2010-09-15 Thread Alan Gauld


"Alex Hall"  wrote


Out of curiosity: I know I can call dll functions from python using
the win32 lib, but is there any way to simply "examine" a loaded dll
to see all of the functions and attributes it exposes for use?


There are various tools around to do that and hopefully some
documentation!

But often nowadays DLLs expose a COM object model and
you have a COM browser built into Pythonwin. That will give
you a windows explorer type view of the objects and their
operations.

If the DLL is purely perocedural then that won't help.

HTH,


--
Alan Gauld
Author of the Learn to Program web site
http://www.alan-g.me.uk/


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


Re: [Tutor] Writing to Sound

2010-09-15 Thread Alan Gauld

"Corey Richardson"  wrote

First off, here is what I'm doing. I'm taking pi (3.141592 etc. etc. 
etc.), taking two values at a time, and then mapping the two values 
to pitch and length. I'm then using winsound.Beep to beep for x ms, 
at y frequency.


So far I understand.


What I want to do, is write that to file.


Write what?
The sound generated by Beep or the data used to drive Beep?

Judging from 
http://codingmess.blogspot.com/2008/07/how-to-make-simple-wav-file-with-python.html, 
it seems to be more complex than I care to undertake without 
exploring the possibilities.


That tells you how to make a wav file that will play in any standard 
media

player program. Is that what you want?


Are there any simpler or higher level ways?


It depends what you want the file to be. What do you intend to do with 
the file?


wouldn't mind something like sound_file.write(freq, length) like 
Beep does, but that may or may not exist.


You can write the two values to a file so that you can read it back 
later
and send the values to Beep. Thats trivial. But the file will not play 
in a

standard player.


I dunno, a simple google doesn't yield anything.


That probably depends on what you are searching for.
I'm not clear from your description what you want to do.

--
Alan Gauld
Author of the Learn to Program web site
http://www.alan-g.me.uk/


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


Re: [Tutor] what happened to the cards module

2010-09-15 Thread Steven D'Aprano
On Wed, 15 Sep 2010 10:09:25 am jsoa...@safe-mail.net wrote:
> I downloaded Python 2.6.6 for windows but I can't access the "Cards"
> module for playing card games.

There is no "Cards" module in the standard library. You'll need to go 
back to wherever you found it in the first place. Google might help.


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


Re: [Tutor] selecting elements from dictionary

2010-09-15 Thread Steven D'Aprano
On Wed, 15 Sep 2010 12:10:59 pm Hs Hs wrote:

> I want to print only those items that have [1,2] and [1,3]  in any
> order, such as [1,2] or [2,1], [3,1] or [1,3]
>
> >>> for item in xdic.keys():
>
> ... if [1,2] in xdic[item]:
> ... print item
>
> I get a wrong answer, 

That's because you ask the wrong question.

[1,2] in xdic[item] doesn't check to see if 1 is in the list, then if 2 
is in the list. It looks to see if one of the items is *exactly* [1,2].

>>> [1,2] in [1,2,3,4]
False
>>> [1,2] in [1,2,3,4, [1,2]]
True


> I know the values are there. How can I print 
> only those item that have [1,2] and [1,3]

for key, value in xdic.items():
if 1 in value and 2 in value or 3 in value:
print key




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


[Tutor] intercepting and recored I/O function calls

2010-09-15 Thread Jojo Mwebaze
Hello Tutor

I would like to intercept and record I/O function calls to a file.. (later
to a database) with probably the names of the files that have been created,
accessed / deleted in my program. I  have not done something like this
before.. Some Guidance is highly appreciated

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


Re: [Tutor] selecting elements from dictionary

2010-09-15 Thread Hs Hs
Dear Steven, 
Thanks for your help. 

however I have a question, 

using:

for key, value in xdic.items():
if 1 in value and 2 in value or 3 in value:
print key


also print keys that have values such as [1,2,3]. 

In cases where there is [1,2,3] and [1,2] also reported. 

How can I extract those keys that have values only [1,2] and [1,3] exclusively. 


>>> xdic = {75796988: [1, 2, 3], 75797478: [1, 2, 3], 75797887:[1,2], 
>>>75797987:[3,1]}
>>> for key, value in xdic.items():
... if 1 in value and 2 in value or 3 in value:
... print key
...
75797987
75796988
75797478
75797887


Here all 4 keys appear. Instead I want to get only 75797887:[1,2] and 
75797987:[3,1]
how can I force this. 

thanks again. 









From: Steven D'Aprano 
To: tutor@python.org
Sent: Wed, September 15, 2010 7:27:05 AM
Subject: Re: [Tutor] selecting elements from dictionary

On Wed, 15 Sep 2010 12:10:59 pm Hs Hs wrote:

> I want to print only those items that have [1,2] and [1,3]  in any
> order, such as [1,2] or [2,1], [3,1] or [1,3]
>
> >>> for item in xdic.keys():
>
> ... if [1,2] in xdic[item]:
> ... print item
>
> I get a wrong answer, 

That's because you ask the wrong question.

[1,2] in xdic[item] doesn't check to see if 1 is in the list, then if 2 
is in the list. It looks to see if one of the items is *exactly* [1,2].

>>> [1,2] in [1,2,3,4]
False
>>> [1,2] in [1,2,3,4, [1,2]]
True


> I know the values are there. How can I print 
> only those item that have [1,2] and [1,3]

for key, value in xdic.items():
if 1 in value and 2 in value or 3 in value:
print key




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



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


Re: [Tutor] selecting elements from dictionary

2010-09-15 Thread Evert Rol
> using:
> 
> for key, value in xdic.items():
> if 1 in value and 2 in value or 3 in value:
> print key
> 
> 
> also print keys that have values such as [1,2,3]. 
> 
> In cases where there is [1,2,3] and [1,2] also reported. 
> 
> How can I extract those keys that have values only [1,2] and [1,3] 
> exclusively.  

If you know that elements in a list are unique (so only appear once), you may 
want to look at using sets.

  Evert


> >>> xdic = {75796988: [1, 2, 3], 75797478: [1, 2, 3], 75797887:[1,2], 
> >>> 75797987:[3,1]}
> >>> for key, value in xdic.items():
> ... if 1 in value and 2 in value or 3 in value:
> ... print key
> ...
> 75797987
> 75796988
> 75797478
> 75797887
> 
> 
> Here all 4 keys appear. Instead I want to get only 75797887:[1,2] and 
> 75797987:[3,1]
> how can I force this. 
> 
> thanks again. 
> 
> 
> 
> 
> 
> From: Steven D'Aprano 
> To: tutor@python.org
> Sent: Wed, September 15, 2010 7:27:05 AM
> Subject: Re: [Tutor] selecting elements from dictionary
> 
> On Wed, 15 Sep 2010 12:10:59 pm Hs Hs wrote:
> 
> > I want to print only those items that have [1,2] and [1,3]  in any
> > order, such as [1,2] or [2,1], [3,1] or [1,3]
> >
> > >>> for item in xdic.keys():
> >
> > ...if [1,2] in xdic[item]:
> > ...print item
> >
> > I get a wrong answer, 
> 
> That's because you ask the wrong question.
> 
> [1,2] in xdic[item] doesn't check to see if 1 is in the list, then if 2 
> is in the list. It looks to see if one of the items is *exactly* [1,2].
> 
> >>> [1,2] in [1,2,3,4]
> False
> >>> [1,2] in [1,2,3,4, [1,2]]
> True
> 
> 
> > I know the values are there. How can I print 
> > only those item that have [1,2] and [1,3]
> 
> for key, value in xdic.items():
> if 1 in value and 2 in value or 3 in value:
> print key
> 
> 
> 
> 
> -- 
> Steven D'Aprano
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
> 
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor

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


Re: [Tutor] selecting elements from dictionary

2010-09-15 Thread Adam Bark

On 15/09/10 15:31, Hs Hs wrote:

Dear Steven,
Thanks for your help.

however I have a question,

using:

for key, value in xdic.items():
if 1 in value and 2 in value or 3 in value:
print key


also print keys that have values such as [1,2,3].

In cases where there is [1,2,3] and [1,2] also reported.

How can I extract those keys that have values only [1,2] and [1,3] 
exclusively.



>>> xdic = {75796988: [1, 2, 3], 75797478: [1, 2, 3], 75797887:[1,2], 
75797987:[3,1]}

>>> for key, value in xdic.items():
... if 1 in value and 2 in value or 3 in value:
... print key
...
75797987
75796988
75797478
75797887


Here all 4 keys appear. Instead I want to get only 75797887:[1,2] and 
75797987:[3,1]

how can I force this.
If you just have a few specific cases you can use "in" to check whether 
the values you are interested in appear in a specified collection, ie:


>>> xdic = {75796988: [1, 2, 3], 75797478: [1, 2, 3], 75797887:[1,2], 
75797987:[3,1]}

>>> for key, value in xdic.items():
... if value in ([1,2], [2,1], [1,3], [3,1]):
... print key
...
75797987
75797887

HTH


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


Re: [Tutor] what happened to the cards module

2010-09-15 Thread Evert Rol
> Hi Evert:
> 
> I've been looking for a card playing framework for a long time. When I saw 
> "import Cards" and that he was shuffling, dealing cards, etc, I immediately 
> downloaded Python. Could this be available in Pygames?

It depends where you "him" shuffling & dealing cards. 
Pygames doesn't exist, pygame does, but probably doesn't have what you're 
looking for.

I do remember a set of questions on this list with a Cards example, but that 
was just some home-written code.

You'll need to check the context of where you saw this, and if it's useful and 
usable to you.
And I certainly don't know what you mean by a card playing framework: do you 
mean (library) code, which language, what "card game"?

  Evert



> Thanks.
> 
> John Soares
> jsoa...@safe-mail.net
> 
>  Original Message 
> From: Evert Rol 
> To: jsoa...@safe-mail.net
> Cc: tutor@python.org
> Subject: Re: [Tutor] what happened to the cards module
> Date: Wed, 15 Sep 2010 10:40:34 +0200
> 
>> I downloaded Python 2.6.6 for windows but I can't access the "Cards" module 
>> for playing card games.
>> 
>> Did it get renamed? If so, how can I find it?
> 
> I don't think there's a Cards module in the standard library. At least, I've 
> never seen it, nor can I find any mention about it on the python 
> documentation page.
> 
> Probably this is a module you installed yourself later on, and is now only 
> accessible for your previous Python version? You would have to reinstall it 
> for Python 2.6.
> How did you previously use Cards? What Python version.
> 
> Btw, I don't know what your upgrade path is, but can't you go to Python 2.7 
> directly?
> 
>  Evert

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


Re: [Tutor] Writing to Sound

2010-09-15 Thread kb1pkl




-Original Message-
From: Alan Gauld 
To: tutor 
Sent: Wed, Sep 15, 2010 5:26 am
Subject: Re: [Tutor] Writing to Sound


"Corey Richardson"  wrote


First off, here is what I'm doing. I'm taking pi (3.141592 etc. etc.
etc.), taking two values at a time, and then mapping the two values
to pitch and length. I'm then using winsound.Beep to beep for x ms,
at y frequency.


So far I understand.


What I want to do, is write that to file.


Write what?
The sound generated by Beep or the data used to drive Beep?

[snip]

--
Alan Gauld
Author of the Learn to Program web site
http://www.alan-g.me.uk/


-


 I want to write the sound generated by Beep to file, or sound at the 
same pitch and length. Sorry that that wasn't clear

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


Re: [Tutor] list dll functions?

2010-09-15 Thread ALAN GAULD
Find the Pythonwin IDE executable and run it - its a better IDE than IDLE in my 
opinion, especially if you are on Windows.

Once it is started you can go to the Tools->COM Browser menu item and 
it starts an explorer type Window. The top level "folders" are:

Registered Objects
Running Objects
Registered Type Libraries

You can then drill down and explore as you wish.
For example under Registered Type Libraries there is Accessibility.
Within that there is TypeLibrary-> IAccessible-Dispatch
Within that there are functions such as  AddRef, Invoke, GetTypeInfo etc.

Inside those you can see the parameters etc.


Alan Gauld
Author of the Learn To Program website
http://www.alan-g.me.uk/




- Original Message 
> From: Alex Hall 
> To: Alan Gauld 
> Sent: Wednesday, 15 September, 2010 15:57:43
> Subject: Re: [Tutor] list dll functions?
> 
> On 9/15/10, Alan Gauld   wrote:
> >
> > "Alex Hall"   wrote
> >
> >> Out of curiosity: I know I can call dll functions from  python using
> >> the win32 lib, but is there any way to simply "examine"  a loaded dll
> >> to see all of the functions and attributes it exposes  for use?
> >
> > There are various tools around to do that and hopefully  some
> > documentation!
> >
> > But often nowadays DLLs expose a COM  object model and
> > you have a COM browser built into Pythonwin. That will  give
> > you a windows explorer type view of the objects and their
> >  operations.
> How would you go about doing that? I have the pywin  extension
> installed for my python installation.
> >
> > If the DLL is  purely perocedural then that won't help.
> >
> >  HTH,
> >
> >
> > --
> > Alan Gauld
> > Author of the Learn  to Program web site
> > http://www.alan-g.me.uk/
> >
> >
> >  ___
> > Tutor maillist   -  Tutor@python.org
> > To unsubscribe or  change subscription options:
> > http://mail.python.org/mailman/listinfo/tutor
> >
> 
> 
> -- 
> Have a great day,
> Alex (msg sent from GMail website)
> mehg...@gmail.com; http://www.facebook.com/mehgcap
> 
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] counting elements in list

2010-09-15 Thread kumar s
Hi group:

I have a list:

 k = ['T', 'C', 'T', 'T', 'T', 'T', 'T', 'T', 'T', 'C', 'T', 'T', 'T', 'C', 
'T', 
'T', 'T', 'C', 'C', 'T', 'T', 'T', 'C', 'T', 'T', 'T', 'T', 'T', 'T']

the allowed elements are A or T or G or C. List can have any number of A or T 
or 
G or C

My aim is to get a string ouput with counts of each type A or T or G or C.  

A:0\tT:23\tG:0\tC:6  

from the above example, I could count T and C and since there are no A and G, I 
want to print 0 for them. I just dont know how this can be done. 




>>> d = {}
>>> for i in set(k):
... d[i] = k.count(i)
...
>>> d
{'C': 6, 'T': 23}


>>> for keys,values in d.items():
... print keys+'\t'+str(d[keys])
...
C   6
T   23

the other way i tried is:
>>> k.count('A'),k.count('T'),k.count('G'),k.count('C')
(0, 23, 0, 6)


 how can I get counts for those elements not represented in list and print 
them.  appreciate your help. 


thanks
kumar



  

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


Re: [Tutor] counting elements in list

2010-09-15 Thread Shashwat Anand
On Wed, Sep 15, 2010 at 1:14 PM, kumar s  wrote:

> Hi group:
>
> I have a list:
>
>  k = ['T', 'C', 'T', 'T', 'T', 'T', 'T', 'T', 'T', 'C', 'T', 'T', 'T', 'C',
> 'T',
> 'T', 'T', 'C', 'C', 'T', 'T', 'T', 'C', 'T', 'T', 'T', 'T', 'T', 'T']
>
> the allowed elements are A or T or G or C. List can have any number of A or
> T or
> G or C
>
> My aim is to get a string ouput with counts of each type A or T or G or C.
>
> A:0\tT:23\tG:0\tC:6
>
> from the above example, I could count T and C and since there are no A and
> G, I
> want to print 0 for them. I just dont know how this can be done.
>

>>> k = ['T', 'C', 'T', 'T', 'T', 'T', 'T', 'T', 'T', 'C', 'T', 'T', 'T',
'C', 'T', 'T', 'T', 'C', 'C', 'T', 'T','T', 'C', 'T', 'T', 'T', 'T', 'T',
'T']
>>> "\t".join(x+":"+str(k.count(x)) for x in 'ATGC')
'A:0\tT:23\tG:0\tC:6'



>
>
>
>
> >>> d = {}
> >>> for i in set(k):
> ... d[i] = k.count(i)
> ...
> >>> d
> {'C': 6, 'T': 23}
>
>
> >>> for keys,values in d.items():
> ... print keys+'\t'+str(d[keys])
> ...
> C   6
> T   23
>
> the other way i tried is:
> >>> k.count('A'),k.count('T'),k.count('G'),k.count('C')
> (0, 23, 0, 6)
>
>
>  how can I get counts for those elements not represented in list and print
> them.  appreciate your help.
>



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



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


[Tutor] First complexity program

2010-09-15 Thread Григор Кол ев
Hi.
I try to make a program to connect my POS system with Geovision video
server. I can connect directly with serial port but on the POS no have
free serial. 
My POS can send information like file on video server. 
I can read this file with Python.

It is first problem:
My script can looking the directory every 10 second and if have new file
can opens it but I think have better way to making it.
 
Next problem is:
If I send the data must open port but port is already open by Geovision.
And second I must take data like input not like output.

Every idea is welcome.
Give me only guidelines.
Who modules i can use and where can read some information. 
-- 
Григор Колев 

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


Re: [Tutor] First complexity program

2010-09-15 Thread Viacheslav Chumushuk
On Wed, Sep 15, 2010 at 09:31:45PM +0300, Григор Колев  
wrote:
> Hi.

Hi, Grigoriy.

> I try to make a program to connect my POS system with Geovision video
> server. I can connect directly with serial port but on the POS no have
> free serial. 
> My POS can send information like file on video server. 
> I can read this file with Python.
> 
> It is first problem:
> My script can looking the directory every 10 second and if have new file
> can opens it but I think have better way to making it.

For monitoring FS try to use pynotify library 
(http://pyinotify.sourceforge.net/).

-- 
Please, use plain text message format contacting me, and
don't use proprietary formats for attachments (such as DOC, XLS)
use PDF, TXT, ODT, HTML instead. Thanks.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] counting elements in list

2010-09-15 Thread Steven D'Aprano
On Thu, 16 Sep 2010 03:23:01 am Shashwat Anand wrote:
> On Wed, Sep 15, 2010 at 1:14 PM, kumar s  wrote:
> > Hi group:
> >
> > I have a list:
> >
> >  k = ['T', 'C', 'T', 'T', 'T', 'T', 'T', 'T', 'T', 'C', 'T', 'T',
> > 'T', 'C', 'T',
> > 'T', 'T', 'C', 'C', 'T', 'T', 'T', 'C', 'T', 'T', 'T', 'T', 'T',
> > 'T']
> >
> > the allowed elements are A or T or G or C. List can have any number
> > of A or T or
> > G or C
> >
> > My aim is to get a string ouput with counts of each type A or T or
> > G or C.
> >
> > A:0\tT:23\tG:0\tC:6
> >
> > from the above example, I could count T and C and since there are
> > no A and G, I
> > want to print 0 for them. I just dont know how this can be done.
> >
> >>> k = ['T', 'C', 'T', 'T', 'T', 'T', 'T', 'T', 'T', 'C', 'T', 'T',
> >>> 'T',
>
> 'C', 'T', 'T', 'T', 'C', 'C', 'T', 'T','T', 'C', 'T', 'T', 'T', 'T',
> 'T', 'T']
>
> >>> "\t".join(x+":"+str(k.count(x)) for x in 'ATGC')
> 'A:0\tT:23\tG:0\tC:6'

Given the extremely low-level of knowledge which the Original Poster's 
question reveals, I think a one-liner like that will probably look 
completely cryptic and mysterious.

I suggest a simple modification of the OP's code:

d = {}
for i in set(k):
d[i] = k.count(i)

for key in 'ATGC':
print key + '\t' + str(d.get(key, 0))



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


Re: [Tutor] intercepting and recored I/O function calls

2010-09-15 Thread Alan Gauld


"Jojo Mwebaze"  wrote

I would like to intercept and record I/O function calls to a file.. 
(later
to a database) with probably the names of the files that have been 
created,
accessed / deleted in my program. I  have not done something like 
this

before.. Some Guidance is highly appreciated


Are you talking about I/O calls in your own app? If so thats fairly
straightforward to do. OTOH If you are talking about capturing all
I/O calls that's a lot harder and if it's a multi-user OS will 
need

administrator privileges.

But this is extremely dependant on the Operating System - you will 
basically

have to intercept the system calls. So, which OS are you using?
And how familiar are you with its API?

Al;so, While you can probably do this in Python but its likely to have
a serious impact on the OS performance, it will slow down the 
performamce
quite noticeably. I'd normally recommend using C for something like 
this.


HTH,

--
Alan Gauld
Author of the Learn to Program web site
http://www.alan-g.me.uk/


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


[Tutor] How to get both 2.6 scripts as well as 3.1 scripts to run at command line?

2010-09-15 Thread Richard D. Moores
64-bit Vista.

I have no problem running 3.1 scripts at the command line. However 2.6
scripts seems to require 2.x. For example, I get this error showing that the
old 2.x print won't do:

C:\P26Working\Finished>solveCubicEquation.py
  File "C:\P26Working\Finished\solveCubicEquation.py", line 19
   print "a is", a
   ^
SyntaxError: invalid syntax

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


Re: [Tutor] How to get both 2.6 scripts as well as 3.1 scripts to run at command line?

2010-09-15 Thread David Hutto
print("a is", a)
or
from future import *
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] How to get both 2.6 scripts as well as 3.1 scripts to run at command line?

2010-09-15 Thread Bill Allen
On Wed, Sep 15, 2010 at 10:35 PM, David Hutto  wrote:

> print("a is", a)
> or
> from future import *
> ___
>

Other than the Python 3 style print function, what else is contained in the
future module?

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


Re: [Tutor] How to get both 2.6 scripts as well as 3.1 scripts to run at command line?

2010-09-15 Thread David Hutto
On Thu, Sep 16, 2010 at 12:02 AM, Bill Allen  wrote:
>
>
> On Wed, Sep 15, 2010 at 10:35 PM, David Hutto  wrote:
>>
>> print("a is", a)
>> or
>> from future import *
>> ___
>
> Other than the Python 3 style print function, what else is contained in the
> future module?

>>> import __future__
>>> help(__future__)

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


[Tutor] working with empty lists

2010-09-15 Thread Rance Hall
Im working on a little piece of test code to test an idea for a larger script.

Here is what I've got so far:

l = []

for i in range(0,10)
l.append(i)

for i in range(0,10)
print('%s. %s' % (i, l[i])


This gives me:

0. 0
1. 1
2. 2  etc

which is what I expect, but what I want is to get something like

0. 1
1. 2
2. 3 .

so that the output is clearly different on either side of the "."

I tried changing the append to l.append(i+1)

which almost worked but the output started with 1. 2  I was curious
what happend to the 0. 1 line

I know this means that I'm not understanding exactly what append actually does.

I know that my ide shows that the list as other functions like insert, etc.

Can someone explain to me whats the best way to add a value to a list
that is not long enough to accept it, without playing with the
indexes, it appears I currently am playing with them.

I know generally that we aren't supposed to care about the indexes but
this is eventually going to be part of a menuing system that displays
the index, so I do have a legit need to care about what is happening
to the list index.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] How to get both 2.6 scripts as well as 3.1 scripts to run at command line?

2010-09-15 Thread Richard D. Moores
On Wed, Sep 15, 2010 at 20:25, Richard D. Moores  wrote:

> 64-bit Vista.
>
> I have no problem running 3.1 scripts at the command line. However 2.6
> scripts seems to require 2.x. For example, I get this error showing that the
> old 2.x print won't do:
>
> C:\P26Working\Finished>solveCubicEquation.py
>   File "C:\P26Working\Finished\solveCubicEquation.py", line 19
>print "a is", a
>^
> SyntaxError: invalid syntax
>
> Dick Moores
>

Seems I was misunderstood.

Some of the scripts written for 2.6 use libraries not yet available for 3.x.
So I want to know not how to modify them, but how to run them at the command
line.

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


Re: [Tutor] working with empty lists

2010-09-15 Thread bob gailer

 On 9/16/2010 12:05 AM, Rance Hall wrote:

Im working on a little piece of test code to test an idea for a larger script.

Here is what I've got so far:

l = []

for i in range(0,10)
 l.append(i)

for i in range(0,10)
 print('%s. %s' % (i, l[i])


This gives me:

0. 0
1. 1
2. 2  etc

which is what I expect, but what I want is to get something like

0. 1
1. 2
2. 3 .

so that the output is clearly different on either side of the "."

I tried changing the append to l.append(i+1)

which almost worked but the output started with 1. 2  I was curious
what happend to the 0. 1 line


It works for me (after adding : at the end of the for statements, and a 
parenthesis at the end of the print call).


>>> l = []
>>> for i in range(0,10)
...l.append(i+1)
...
>>> for i in range(0,10)
...print('%s. %s' % (i, l[i]))
...
0. 1
1. 2
2. 3
3. 4

etc.

[snip]

--
Bob Gailer
919-636-4239
Chapel Hill NC

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


Re: [Tutor] How to get both 2.6 scripts as well as 3.1 scripts to run at command line?

2010-09-15 Thread David Hutto
On Thu, Sep 16, 2010 at 12:11 AM, Richard D. Moores  wrote:
>
>
> On Wed, Sep 15, 2010 at 20:25, Richard D. Moores  wrote:
>>
>> 64-bit Vista.
>>
>> I have no problem running 3.1 scripts at the command line. However 2.6
>> scripts seems to require 2.x. For example, I get this error showing that the
>> old 2.x print won't do:
>>
>> C:\P26Working\Finished>solveCubicEquation.py
>>  File "C:\P26Working\Finished\solveCubicEquation.py", line 19
>>    print "a is", a
>>               ^
>> SyntaxError: invalid syntax
>>
>> Dick Moores
>
> Seems I was misunderstood.
>
> Some of the scripts written for 2.6 use libraries not yet available for 3.x.
> So I want to know not how to modify them, but how to run them at the command
> line.
>
> Dick
>
> ___
> Tutor maillist  -  tu...@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>
>

I'm not experienced enough to have utilized all features but it does
seem there would be a way to import and after a quick google search I
think this might be the answer:

http://docs.python.org/using/cmdline.html#envvar-PYTHONSTARTUP

>From my brief review of it, it should call from future automatically
in each interactive session

I'll probably look further because it interests me as well.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor