[Tutor] monodevelop 2.2

2010-08-21 Thread Thomas
I was wondering if someone could tell me if you can use the gui designer 
in monodevelop 2.2+ with python.


Thanks,
Thomas

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


[Tutor] pyGtk using combobox

2006-02-10 Thread thomas
Hi,

I would like to make a combobox with a list of strings, but I have many
problems with it.  I know how to make the combobox and how to add
strings, but is it possible to get a list of strings from the combobox
and also is it possible to update the combobox with a list of strings?
(something like combo.set_popdown_strings(list))
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] property built-in

2006-10-19 Thread thomas
Hi,


I was wondering some things about property.

suppose I have a class like this:

class A(object):
def __init__(self, x, y):
   self.__x = x

def x():
   def get(self):
  return self.__x

   def set(self, x):
  self.__x = x
  #and some other code that is important

x= property(**x())

questions:
1: why doesn't there have to be a self in x()?
2: how do I address the setter of x in the init?

I think these are basic questions, but I can't seem to find out how to 
do it.


Thanks
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Read the builtin module source, also itchy ellipses.

2006-11-17 Thread Thomas

Hi,

I sometimes find it useful to read the source code of a module and for
example I can type string.__file__ to find the location of the string
module.

However the .__file__ method is not available for the module builtin. Is it
possible to read the source code for built in functions and if so how do I
find them? I realise some/all may be written in C rather than python but it
would still be interesting to read them.

In an unrelated follow-up may I also ask: can the ellipsis (...) be used in
code? I tried a googlecode search but none of the examples worked for me.
Can someone post an example line of code that uses ... in it. This has
been causing an itch in my brain, please reply with the scratch.

Thanks in advance,
Tom
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] A Million Sevens

2006-11-17 Thread Thomas

Earlier today I typed the following into my pythonwin interactive
interpreter in windows xp:


int('7' * 10 ** 6)


I expected either an error message or it to get stuck and require me to
stop the process manually.

I read that unlike long integers in C, longs in python are only limited by
the amount of memory (and virtual memory) your system has.

Can you guess what it did?

I'm temped to end the post here, but I'm new to this list and its possible
that people might be annoyed by me not getting to the point within my
initial post, so here's what it did:

It thought about it for about 2 seconds then restarted my pc! explanations
welcome.
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] A Million Sevens

2006-11-17 Thread Thomas
On 18/11/06, Chris Hengge <[EMAIL PROTECTED]> wrote:
> Not that it changes your reply, but just for my own sanity:
> int('7' * 10 ** 6) <- does this not just type-cast a char into an int?
>
> Meaning that rather then consuming 1024k as you stated, it would consume 
> 2048k at the peak of the calculation(2bytes per char? * 1m = 2048k) then 
> typecasting to int would drop it back down to 1k (1byte per int * 1m = 1024k
>
> So, just for sake of getting to a point since I missed the one by the 
> original poster.. why would you not convert that 7 from a char to an int 
> first? That calculation is almost instant, and it doesn't require the memory 
> rollercoaster that this calculation would require..
>
> Anyways.. back to the poster...

Thanks, original poster here, I was just reading my new book, Core
Python Programming (2nd Edition) and it said that there was no
in-built limit to the size of a long in python (as compared to C) so I
wanted to test it out. I just typed the first way of getting a massive
number that came into my head.

> Perhaps you wanted an error like this?
>
> print '=' * 10
> Traceback (most recent call last):
>   File "", line 1, in ?
> MemoryError

Now that is exactly what I thought I might get. I'll try it again with
some of the variations mentioned on Monday when I get back to that
computer.
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] difflib.SequenceMatcher with get_matching_blocks is incorrect

2006-12-04 Thread Thomas
I'm trying to write a program to test someone's typing speed and show
them their mistakes. However I'm getting weird results when looking
for the differences in longer (than 100 chars) strings:

import difflib

# a tape measure string (just makes it easier to locate a given index)
a = 
'1-3-5-7-9-12-15-18-21-24-27-30-33-36-39-42-45-48-51-54-57-60-63-66-69-72-75-78-81-84-87-90-93-96-99-103-107-111-115-119-123-127-131-135-139-143-147-151-155-159-163-167-171-175-179-183-187-191-195--200'

# now with a few mistakes
b = 
'1-3-5-7-l-12-15-18-21-24-27-30-33-36-39o42-45-48-51-54-57-60-63-66-69-72-75-78-81-84-8k-90-93-96-9l-103-107-111-115-119-12b-1v7-131-135-139-143-147-151-m55-159-163-167-a71-175j179-183-187-191-195--200'

s = difflib.SequenceMatcher(None, a ,b)
ms = s.get_matching_blocks()

print ms


[(0, 0, 8), (200, 200, 0)]


Have I made a mistake or is this function designed to give up when the
input strings get too long?

Thanks in advance,
Thomas
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Organizing 15500 records, how?

2006-12-12 Thread Thomas
I'm writing a program to analyse the profiles of the 15500 users of my
forum. I have the profiles as html files stored locally and I'm using
ClientForm to extract the various details from the html form in each
file.

My goal is to identify lurking spammers but also to learn how to
better spot spammers by calculating statistical correlations in the
data against known spammers.

I need advise with how to organise my data. There are 50 fields in
each profile, some fields will be much more use than others so I
though about creating say 10 files to start off with that contained
dictionaries of userid to field value. That way I'm dealing with 10 to
50 files instead of 15500.

Also, I am inexperienced with using classes but eager to learn and
wonder if they would be any help in this case.

Any advise much appreciated and thanks in advance,
Thomas
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] regex eats even when not hungry

2007-02-16 Thread Thomas
I have the following mostly working function to strip the first 4
digit year out of some text. But a leading space confounds it for
years starting 20..:

import re
def getyear(text):
s = """(?:.*?(19\d\d)|(20\d\d).*?)"""
p = re.compile(s,re.IGNORECASE|re.DOTALL) #|re.VERBOSE
y = p.match(text)
try:
return y.group(1) or y.group(2)
except:
return ''



>>> getyear('2002')
'2002'
>>> getyear(' 2002')
''
>>> getyear(' 1902')
'1902'

A regex of ".*?" means any number of any characters, with a non-greedy
hunger (so to speak) right?

Any ideas on what is causing this to fail?

Many thanks in advance,
Thomas
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Building VST's with Python

2009-04-16 Thread Logan Thomas
I'm new to python but do have a little programming knowledge with C++I
got into programming so I could build Virtual Instruments because I love the
world of sound and creating instruments that shape it...I have tried to find
a program that would be an ideal vehicle for this task...I've narrowed it
down to Delphi or PythonC++ would take too long for me to learn and
would take to long to build an application...I was wondering if you could
direct me to some tutorials or source code that might involve building
virtual instruments or even gamesThanks for listening, Logan
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Saving class instances

2009-07-13 Thread Thomas Scrace

Hi everyone,

I am new to Python (and to programming) and, now that I have worked  
through most of Learning Python, I have set myself the exercise of  
writing a little text-based program to catalogue the contents of my CD  
collection.


I have written enough code to allow me to create instances of an Album  
class with attributes like name, artist, year etc.  However, I am at a  
loss as to how to save these instances so that they can be retrieved  
the next time I run the program.  I assume I need to write them to a  
file somehow, and while I know how to write and read to and from  
files, I do not know how to write instances.


I am sure this has an obvious and easy answer but I just cannot find  
it anywhere!


If anybody could help I would be most grateful.

Tom
On 13 Jul 2009, at 14:44, tutor-requ...@python.org wrote:


Send Tutor mailing list submissions to
tutor@python.org

To subscribe or unsubscribe via the World Wide Web, visit
http://mail.python.org/mailman/listinfo/tutor
or, via email, send a message with subject or body 'help' to
tutor-requ...@python.org

You can reach the person managing the list at
tutor-ow...@python.org

When replying, please edit your Subject line so it is more specific
than "Re: Contents of Tutor digest..."


Today's Topics:

  1. Re: for statement with addition ... (Rommel Asibal)
  2. Re: for statement with addition ... (Kent Johnson)
  3. Xampp & Python (Rommel Asibal)
  4. Re: thesaurus (Dave Angel)
  5. Re: for statement with addition ... (Dave Angel)
  6. Re: for statement with addition ... (Markus Hubig)


--

Message: 1
Date: Mon, 13 Jul 2009 05:22:28 -0600
From: Rommel Asibal 
To: Markus Hubig 
Cc: tutor@python.org
Subject: Re: [Tutor] for statement with addition ...
Message-ID:

Content-Type: text/plain; charset="iso-8859-1"

Markus,

That looks like a typo.  remove it and it should work.

On Mon, Jul 13, 2009 at 4:50 AM, Markus Hubig   
wrote:



Hi @all,

within diveintopython I often found a for-statement like this:

f for f in bla:
   print f

So what actually is the first f for ... is it just to declare f  
before

starting the for loop? I can't find any information on python.org
and it's hard to google this kinda stuff.

- Markus

--
---"it's like this"--
even samurai have teddy bears
and even teddy bears get drunk

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor



-- next part --
An HTML attachment was scrubbed...
URL: 


--

Message: 2
Date: Mon, 13 Jul 2009 07:37:45 -0400
From: Kent Johnson 
To: Markus Hubig 
Cc: tutor@python.org
Subject: Re: [Tutor] for statement with addition ...
Message-ID:
<1c2a2c590907130437y4f19d357r811d0c956b53e...@mail.gmail.com>
Content-Type: text/plain; charset=ISO-8859-1

On Mon, Jul 13, 2009 at 6:50 AM, Markus Hubig wrote:

Hi @all,

within diveintopython I often found a for-statement like this:

f for f in bla:
??? print f

So what actually is the first f for ... is it just to declare f  
before

starting the for loop? I can't find any information on python.org
and it's hard to google this kinda stuff.


That is not Python, maybe a copy/paste artifact? Omit the initial 'f
'. Can you point to an example on the web site or in the printed book?

Kent


--

Message: 3
Date: Mon, 13 Jul 2009 05:56:46 -0600
From: Rommel Asibal 
To: Python Tutor List 
Subject: [Tutor] Xampp & Python
Message-ID:

Content-Type: text/plain; charset="iso-8859-1"

Hello All,

I am trying to go through the "Python Power!" book and i am at the  
part
where i need to setup a web server.  I am thinking of using XAMPP  
and have
checked its site and wanted to try using mod_python.  I am using  
Python 3.1
but from initial looks it seems mod_python doesnt support it, could  
someone
verify if that is correct?  Does that mean i have to go to python  
2.6 for it

to work?


Thanks!
-- next part --
An HTML attachment was scrubbed...
URL: 


--

Message: 4
Date: Mon, 13 Jul 2009 07:57:54 -0400
From: Dave Angel 
To: Pete Froslie 
Cc: Alan Gauld , tutor@python.org, Dave
Angel 
Subject: Re: [Tutor] thesaurus
Message-ID: <4a5b2142.7080...@ieee.org>
Content-Type: text/plain; charset=UTF-8; format=flowed

Pete Froslie wrote:

The url function btw:

def url():


  fin = open("journey_test.txt", "r")
  response = re.split(r"[/|/,\n, , ,:\"\"\.?,)(\-\<>\[\]'\r']",
fin.read())
  thesaurus = API_URL + response[word_number] + '/'  #API_URL is
established at the start of the code
  return thesaurus


yes. Essentially, it grab

Re: [Tutor] Saving class instances

2009-07-13 Thread Thomas Scrace
I think I will give both approaches a go, since this is just a  
learning exercise anyway.  Thanks very much for your help.


Oh, and sorry for accidentally quoting the whole digest last time.   
Won't happen again!


Tom

On 13 Jul 2009, at 17:53, tutor-requ...@python.org wrote:

I think you are better off using a database in this situation,  
sqlite3 is a

good choice since no extra setup is required. See
http://docs.python.org/library/sqlite3.html

And to answer your question, the python pickle module can save class
instances, see http://docs.python.org/library/pickle.html


Regards,
Daniel Woodhouse


___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Saving class instances

2009-07-14 Thread Thomas Scrace


On 13 Jul 2009, at 22:04, "Alan Gauld"   
wrote:



That's one way and you can find an example and some advice
on how to handle subclassing in the OOP topic of my tutor.



Wow; thanks!  That tutorial  was really useful, I will have to check  
out the rest

of the site now.


I am sure this has an obvious and easy answer but I just cannot find
it anywhere!


Actually no. Saving and retrieving object instances (known as
persisting objects in OOP speak) was one of the biggest challenges
facing the OOP paradigm when it got started in the real world. Many
different solutions have evolved from flat text files to dedicated  
Object

databases, and everyting in between, but it remains a task frought
with difficulty, especially on large scale projects.



Good to know I wasn't being totally dense.  Now that I have got the  
pickle thing

under my belt I am going to have a go at sqllite.

Thanks again everybody.

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] executing SAS and passing parameters

2005-02-08 Thread Williams, Thomas








Greetings,

 

I am
trying to use python to run a SAS program by passing the needed
parameters.  I am able to start SAS, but unable to start the correct SAS
program with its parameters.

 

Any
assistance you could provide will be appreciated.

 

Tom Williams
DSHS - Research and Data Analysis
Division 
14th and Jefferson, MS: 45204 
  Olympia, WA 
 98504-5204

360.902.0764

 






___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


RE: [Tutor] executing SAS and passing parameters

2005-02-08 Thread Williams, Thomas
I'll do my best to answer these questions for you.

I am able to start the SAS executable from python, but not the specific SAS
program in question.  When this executable is executed, the typical SAS
environment is displayed (SAS editor Window, SAS libraries, and the output
and log windows).  I want to have a specific SAS program executing with the
assigned parameters that will be read into a SAS macro.  

This SAS program was originally called from an AML (Arc Macro Language),
again, with the parameters passed to it.

OS: WindowsNT

Let me know if you need further information.

Thanks again,
Tom


-Original Message-
From: Alan Gauld [mailto:[EMAIL PROTECTED] 
Sent: Tuesday, February 08, 2005 1:57 PM
To: Williams, Thomas; tutor@python.org
Subject: Re: [Tutor] executing SAS and passing parameters

> I am trying to use python to run a SAS program by passing the needed
> parameters.  I am able to start SAS, but unable to start the correct
SAS
> program with its parameters.

Not being familiar with SAS or its parameters we'll need more clues...

> Any assistance you could provide will be appreciated.

Can you show us what you used to start SAS?
Can you tell us exactly what happened? - any errors etc?
Can you show us how you'd do it outside of Python?
Can you tell us which OS you are using?

With that info we should be able to make a stab at it.

Alan G.


___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] executing SAS and passing parameters

2005-02-09 Thread Williams, Thomas
Here is the code I am using to invoke SAS:

import os
import sys

shell = os.environ.get('COMSPEC')
if shell is None: shell = os.environ.get('SHELL')
if shell is None: shell = 'an unknown command processor'
print 'Running under', shell

os.execl('C:\Program Files\SAS Institute\SAS\V8\SAS.exe')


However, the program in question is c:\work\run_ratios.sas, with 2
parameters: incov, and outcov.  This program was initially invoked from an
aml program.  The code that invoked SAS from this aml is:

&SYSTEM %.SASLOC% -SYSPARM %sas_parm% -log ~
%.ARCLOC%\ratios\log\%.file%.log -SYSIN ~
%.ARCLOC%\sas_code\ratios\new_ratio.sas

%.SASLOC%: the SAS executable file ('C:\Program Files\SAS
Institute\SAS\V8\SAS.exe')
%sas_parm%: the list of parameters to be passed onto SAS
%.file%: the name of the log file that is generated during the execution of
the SAS program.
%.ARCLOC%: directory of the SAS program (c:\work)

I think this is an excellent forum to share ideas and solve problems.  Thank
you ever so much for your assistance with this.


___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] updating Oracle tables via python

2005-03-29 Thread Williams, Thomas








Greetings,

I am attempting to update an Oracle table
using python.  When I execute the code, the python script appears to hang,
in that nothing else happens.

 

As always, any assistance you can provide
will be appreciated.

 

Code:

 

connection = cx_Oracle.connect("db/[EMAIL PROTECTED]")

cursor = connection.cursor()

strUpdate = " UPDATE table SET firstname
= 'JOSEPH'  WHERE lastname = 'SMITH' "

cursor.execute(strUpdate)

cursor.close()

connection.close()

 

 

Tom Williams
DSHS - Research and Data Analysis
Division 
14th and Jefferson, MS: 45204 
  Olympia, WA 
 98504-5204

360.902.0764

 






___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Cryptography Toolkit

2005-03-31 Thread Mark Thomas
Does anyone have some examples on the use of A.M. Kuchling's Python
Cryptography Toolkit? I've tried his examples but get "AttributeError"
and "TypeError". What I'm trying to do is encrypt/decrypt a file. I'm
using Python 2.3 on xp pro.

Thanks
-- 
 _
( ) Mark Thomas ASCII ribbon campaign
 X www.theswamp.org   - against HTML email
/ \
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Cryptography Toolkit

2005-03-31 Thread Mark Thomas
On Thu, 31 Mar 2005 09:14:03 -0500, Kent Johnson <[EMAIL PROTECTED]> wrote:
> If you post your code and the complete error message including the stack 
> trace we may be able to help.
> 
> Kent

Thanks Ken

I'm getting closer to making this work using the XOR cipher. Here's
what I'm doing.



from Crypto.Cipher import XOR

obj_xor = XOR.new("string")
str_encrypt = "encrypt this string"
xored = obj_xor.encrypt(str_encrypt)
xored
'\x16\x1a\x11\x1b\x17\x17\x07T\x06\x01\x07\x14S\x07\x06\x1b\x07\t\x14'
obj_xor.decrypt(xored)
"bhxupds&oo`g'uou`z`" <== *confused by this output*



Close but no cigar!! *grin*

-- 
 _
( ) Mark Thomas ASCII ribbon campaign
 X www.theswamp.org   - against HTML email
/ \
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Cryptography Toolkit

2005-04-01 Thread Mark Thomas
On Apr 1, 2005 6:45 AM, Kent Johnson <[EMAIL PROTECTED]> wrote:
> It works if you make a new XOR object for the decryption:
> 
> from Crypto.Cipher import XOR
> 
> obj_xor = XOR.new("string")
> str_encrypt = "encrypt this string"
> print str_encrypt
> 
> xored = obj_xor.encrypt(str_encrypt)
> print xored
> 
> obj_xor = XOR.new("string")
> print obj_xor.decrypt(xored)
> 
> Kent

Excellent !!
Many thanks Kent.
-- 
 _
( ) Mark Thomas ASCII ribbon campaign
  X www.theswamp.org   - against HTML email
/ \
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] website information

2005-04-18 Thread Williams, Thomas








Does anyone know how to prevent this error
from occurring: IOError: [Errno socket error] (10060, 'Operation timed out'). 

 

I have searched for solutions without any
success.

 

Tom Williams

 

 






___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Simple string processing problem

2005-05-13 Thread Mark Thomas
On 13 May 2005 21:59:58 +0100, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
> The file:
> 
> ScerACTAACAAGCTGGTTTCTCC-TAGTACTGCTGTTTCTCAAGCTG
> Sparactaacaagctggtttctcc-tagtactgctgtttctcaagctg
> Smikactaacaagctgtttcctcttgaaatagtactgctgcttctcaagctg
> Sbayactaacaagcactgattgaaatagtactgctgtctctcaagctg
>   * ** **     ***   * ***  *
> 
> ScerTGCTCACCAATTTATCCCAATTGGTTTCGGTATCAAGAAGTTGCAAATTAACTGTG
> SparTGCTCACCAATTTATCCCAATTGGTTTCGGTATCAAGAAGTTGCAAATTAACTGTG
> SmikTGCTCACCAATTCATCCCAATTGGTTTCGGTATCAAGAAGTTGCAAATTAACTGTG
> SbayTGCTCACCAATTCATCCCAATTGGTTTCGGTATCAAGAAATTGCAAATTAACTGTG
> * ** *   *   *  ** * ** 
> 
> ScerACCACGTCCAATCTACCGATATTGCTGCTATGCATTATAAaaggctt-ataa
> SparACCACGTCCAATCTACCGATATTGCTGCTATGCATTATAAaaagctttataa
> SmikACCACGTCCAATCTACCGATATTGCTGCTATGCATTATAAgaagctctataa
> SbayACCACGTCCAATCTACCGATATTGCTGCTATGCATTATAAgaagctctataa
>  * ***  
> 
> Sceractataattaacattaa---agcacaacattgtaaagattaaca
> Sparactataataaacatcaa---agcacaacattgtaaagattaaca
> Smikactataattaacatcgacacgacaacaacaacattgtaaagattaaca
> Sbayactataacttagcaacaacaacaacaacaacatcaacaacattgtaaagattaaca
> ***     * **  **

How about some RE action.

>>> import re
>>> pat = re.compile('^(S[a-z]{3}\s*[A-Z]+).*$')
>>> fr = file('dna','r')
>>> for line in fr:
... m = pat.match(line)
... if m:
... print m.group(1)
...
ScerACTAACAAGCTGGTTTCTCC
ScerTGCTCACCAATTTATCCCAATTGGTTTCGGTATCAAGAAGTTGCAAATTAACTGTG
SparTGCTCACCAATTTATCCCAATTGGTTTCGGTATCAAGAAGTTGCAAATTAACTGTG
SmikTGCTCACCAATTCATCCCAATTGGTTTCGGTATCAAGAAGTTGCAAATTAACTGTG
SbayTGCTCACCAATTCATCCCAATTGGTTTCGGTATCAAGAAATTGCAAATTAACTGTG
ScerACCACGTCCAATCTACCGATATTGCTGCTATGCATTATAA
SparACCACGTCCAATCTACCGATATTGCTGCTATGCATTATAA
SmikACCACGTCCAATCTACCGATATTGCTGCTATGCATTATAA
SbayACCACGTCCAATCTACCGATATTGCTGCTATGCATTATAA


-- 
 _
( ) Mark Thomas ASCII ribbon campaign
 X www.theswamp.org   - against HTML email
/ \
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] (no subject)

2005-07-06 Thread Mark Thomas
On 7/6/05, Michael Huster <[EMAIL PROTECTED]> wrote:
> In python under windows, how can I create and access a file on the Desktop? 
> The following do NOT work:
 
How about...

>>> userp = os.getenv('USERPROFILE') + '\\Desktop\\MyFile.txt'
>>> fo = file(userp, 'w')
-- 
 _
( ) Mark Thomas ASCII ribbon campaign
 X www.theswamp.org   - against HTML email
/ \
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Windows Python 2.5.1 IPV6 problems

2008-02-02 Thread Thomas DiZoglio
Hi,

I'm trying to get some IPV6 python code running under
Windows. I have installed Python 2.5.1 for Windows
using the binaries from python.org. I'm a newbie to
Python programming as well.

The code works fine under Debian and MacOSX (both
using Python 2.5)

I have rebuilt the python binaries from source and set
ENABLE_IPV6. This didn't help. I have also read about
not being able to bind to a IPV4 and IPV6 socket. I
tried setting the setsockopt() call using IPV6_V6ONLY,
but this is not recognized by the python interpreter.

Thanks for any help I can get. I'm stuck on this and
searching the NET for help.

I get the following error:

C:\test_py>python ipv6.py
Traceback (most recent call last):
  File "ipv6.py", line 119, in 
main()
  File "ipv6.py", line 113, in main
p = listenTCP6(, TrivialServerFactory())
  File "ipv6.py", line 95, in listenTCP6
return reactor.listenWith(Port, port, factory,
backlog, interface)
  File
"C:\python251\lib\site-packages\twisted\internet\posixbase.py",
line 499,
 in listenWith
p.startListening()
  File
"C:\python251\lib\site-packages\twisted\internet\tcp.py",
line 730, in st
artListening
skt = self.createInternetSocket()
  File
"C:\python251\lib\site-packages\twisted\internet\tcp.py",
line 718, in cr
eateInternetSocket
s = base.BasePort.createInternetSocket(self)
  File
"C:\python251\lib\site-packages\twisted\internet\base.py",
line 724, in c
reateInternetSocket
s = socket.socket(self.addressFamily,
self.socketType)
  File "C:\Python251\lib\socket.py", line 154, in
__init__
_sock = _realsocket(family, type, proto)
TypeError: an integer is required


Thanks.
-
t0md

I run with the following command:
python ipv6.py


HERE IS THE CODE for ipv6.py:


#this is copied verbatim from
http://twistedmatrix.com/trac/browser/sandbox/exarkun/ipv6.py
#I'm unclear on the license that applies

import socket
from twisted.internet import tcp
from twisted.internet import protocol
from twisted.internet import reactor

class IPv6Address(object):
def __init__(self, type, host, port, flowInfo,
scope):
self.type = type
self.host = host
self.port = port
self.flowInfo = flowInfo
self.scope = scope

def __eq__(self, other):
if isinstance(other, IPv6Address):
a = (self.type, self.host, self.port,
self.flowInfo, self.scope)
b = (other.type, other.host, other.port,
other.flowInfo, other.scope)
return a == b
return False

def __str__(self):
return 'IPv6Address(%s, %r, %d, %d, %d)' % (
self.type, self.host, self.port,
self.flowInfo, self.scope)

def isIPv6Address(ip):
try:
socket.inet_pton(socket.AF_INET6, ip)
except:
return 0
return 1

class Client(tcp.Client):
addressFamily = socket.AF_INET6

def resolveAddress(self):
if isIPv6Address(self.addr[0]):
self._setRealAddress(self.addr[0])
else:
   
reactor.resolve(self.addr[0]).addCallbacks(
self._setRealAddress,
self.failIfNotConnected
)

def getHost(self):
return IPv6Address('TCP',
*self.socket.getsockname())

def getPeer(self):
return IPv6Address('TCP',
*self.socket.getpeername())


class Connector(tcp.Connector):
def _makeTransport(self):
return Client(self.host, self.port,
self.bindAddress, self, self.reactor)

def getDestination(self):
return IPv6Address('TCP', self.host,
self.port, 0, 0)

class Server(tcp.Server):
def getHost(self):
return IPv6Address('TCP',
*self.socket.getsockname())

def getPeer(self):
return IPv6Address('TCP', *self.client)

class Port(tcp.Port):
addressFamily = socket.AF_INET6

transport = Server

def _buildAddr(self, address):
return IPv6Address('TCP', *address)

def getHost(self):
return IPv6Address('TCP',
*self.socket.getsockname())

def getPeer(self):
return IPv6Address('TCP',
*self.socket.getpeername())

def connectTCP6(host, port, factory, timeout=30,
bindAddress=None, reactor=None):
if reactor is None:
from twisted.internet import reactor
return reactor.connectWith(
Connector, host, port, factory, timeout,
bindAddress
)


def listenTCP6(port, factory, backlog=5,
interface='::', reactor=None):
if reactor is None:
from twisted.internet import reactor
#IPV6_V6ONLY = 27, IPV6_BINDV6ONLY
#IPPROTO_IPV6 = 41
#_socket.socket.setsockopt(_socket.IPPROTO_IPV6,
_socket.IPV6_V6ONLY, 0)
return reactor.listenWith(Port, port, factory,
backlog, interface)

def main():
from twisted.internet import reactor

class TrivialProtocol(protocol.Protocol):
def connectionMade(self):
print 'I (', self.transport.getHost(), ')
am connected! (to ', self.transport.getPeer(), ')'
  

Re: [Tutor] Bad time to get into Python?

2008-02-03 Thread Thomas Pani
Dotan Cohen wrote:
> However, with the coming of Python3 and the new syntax, is this a bad time to 
> start learning Python?
Not at all, I'd say. Changes will be fairly small, with the main changes
being:
 - print is replaced by a print() function
 - / will become the float division operator
 - changes towards iterators (e.g. range() doesn't return a list)
 - string filetype changes
There are lots of other changes, but most of them include removing
already deprecated idioms. [1] has a list of Python 3k changes.
There's also the 2to3 conversion tool which allows you to run lots of
conversion automated.

> That asked, I've heard that 2.6 can be configured to warn when using
> code that will not run in 3.x. Is this correct?
Yes, 2.6 will support a "Py3k warnings mode". It should also have many
of 3k's features already implemented, allowing to run both side-by-side
or via __future__. PEP 3000 ([2]) has more info on this.

> How is this done? I'd like to do it on a per-file basis, so that I will
> only need to run one version of python on this machine.
Don't know. But if your only using it for some home-coding, you would
just once do the conversion and then update to 3k.

> I want my own apps to throw errors,
> but not other python apps on this system. Is there some error-level
> code that I can run?
Not sure what you mean by that. Are you refering to exception-handling?

I'd say it's not a bad time to learn Python. There will be some major
changes in 3k, but as long as you don't have to maintain 2.6 and 3.0 in
parallel, conversion should be easy enough.

Cheers,
thomas pani

[1] http://docs.python.org/dev/3.0/whatsnew/3.0.html
[2] http://www.python.org/dev/peps/pep-3000/
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] A bit about python culture

2008-02-07 Thread Thomas B.Døderlein
>Michael Bernhard Arp Sørensen wrote:
>> Greetings Masters.
>> 
>> I was wondering if there's a well know word for python programmers, that 
>> is usable as a domain name.
>
>Pythonista is one. pythonista.dk seems to be available.
>
>Kent

Other available  .dk domains

pyproject.dk

pyprojects.dk

python-project.dk

pythonprogram.dk


These might be used for project subdomains, then the programmers might add 
their name in E-mail adresses. Doing this you will also marked Python projects 
+ making people aware of Python as a programming language. Just a thought :)



BR
Thomas




>___
>Tutor maillist  -  Tutor@python.org
>http://mail.python.org/mailman/listinfo/tutor

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] opening a pipe?

2008-02-12 Thread Thomas Pani
The subprocess module is what you're looking for.
Your example would look like

%<
import subprocess
p = subprocess.Popen('cat hi.txt', shell=True, stdout=subprocess.PIPE)
for line in p.stdout:
 print line
%<

I assume you know that you can just open a file for reading instead of 
piping cat.

thomas

James Hartley wrote:
> A Perl script can easily serve as a filter within a pipe as seen in
> the following:
> 
> use strict;
> use warnings;
> 
> open(IN, 'cat hello.txt |') or die 'unable to open file';
> while () {
> print;
> }
> close(IN);
> 
> Can I do the same within Python?  Thanks.
> 
> Jim
> ___
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor


___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Question on multithreading

2008-02-24 Thread Thomas Pani
Hi,

Here are some thoughts:

 From the Python Library Reference: "If the subclass overrides the 
constructor, it must make sure to invoke the base class constructor 
(Thread.__init__()) before doing anything else to the thread." You'll 
have to do that for your GuiScript class.

You can't just stop a thread, you can only wait for it to finish using 
join(). Or you can set its deamon flag, so it will exit when no 
non-daemon threads are left.

Is there any reason for starting the GUI code in a separate thread? You 
could just leave it in the main thread.

For some general notes on this topic this might be helpful:
http://wiki.wxpython.org/LongRunningTasks

Cheers,
Thomas Pani

Varsha Purohit wrote:
> Hello,
> i have a gui program in wxpython where i am spawning two threads. 
> one for the mainloop of gui and other for some background tasks. I have 
> to stop the background running thread once its work is done. I am trying 
> to use the join method but it is giving me an error saying threads 
> cannot be joined as the thread has just been created... whereas at that 
> point the thread is done with its job. So i am confused whether i am 
> putting it correctly or not. also, is there any method called stop() to 
> stop the threadsAlso, i want to see if the thread is alive or not.. 
> but i donno where should i put the isAlive() method associated with the 
> thread.. i tried putting it in the code where thread does execution but 
> apparently it is not the correct place.
> 
> Here is the code...
> 
> class GuiScript(threading.Thread):
> def __init__(self):
> self.run()
> def run(self):
> app = wx.PySimpleApp()
> MainWindow().Show()
> app.MainLoop()
>
> class RunScript(threading.Thread):
> def run(self):
> imFile=test()
>
> and when the stop button is pressed the two threads should stop 
> executing... so i have written code like this...
> 
> def OnCloseWindow(self,event):
> GuiScript().Stop()
> RunScript().Stop()
> self.Destroy()
> 
> but seems stop() method is not existing... can anybody guide me pl
> 
> thanks,
>   
> 
> -- 
> Varsha Purohit,
> Graduate Student
> 
> 
> 
> 
> ___
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor


___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] How to strip both single and double quotes

2005-10-05 Thread Mark Thomas
On 10/5/05, Dick Moores <[EMAIL PROTECTED]> wrote:
> The text will contain "words" beginning or ending with non-alphabetic
> characters. To strip them off I use string.strip([chars]). My question is
> how to use strip just once to get rid of both kinds of quotes, single and
> double. It seems necessary to do it something like this:

Not sure what you mean by 'words' but how about something like this.
[x.strip('\' \" () * & ^ % $ # < ') for x in word.split()]

Example:
>>> str = 'this has special characters \" \' ()*&^%$# << '
>>> [x.strip('\' \" () * & ^ % $ # < ') for x in str.split()]
['this', 'has', 'special', 'characters', '', '', '', '']

--
 _
( ) Mark Thomas ASCII ribbon campaign
 X www.theswamp.org   - against HTML email
/ \
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] New Tutorial topic available

2006-02-26 Thread Mark Thomas
On 2/26/06, Alan Gauld <[EMAIL PROTECTED]> wrote:
> I've just uploaded the latest tutorial topic covering inter-process
> communications. It covers pipes and the use of fork().
>
> Enjoy, as ever feedback is welcomed.

Thanks Alan, your pages are a great source of information for us newbies.

--
 _
( ) Mark Thomas ASCII ribbon campaign
 X www.theswamp.org   - against HTML email
/ \
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Problems with a Class

2007-01-13 Thread thomas coopman
On Sat, 13 Jan 2007 01:08:53 +0100
Carlos <[EMAIL PROTECTED]> wrote:

> Hello,
> 
> I'm just about to finish my project, but something is causing me 
> trouble. I need to find out how to get some information out of the 
> genetic algorithm that Im using. This algorithm is generating some 
> coordinates for a collection of objects, until now I needed only the 
> final result of the process. But I discovered that the final
> information is not enough, I need to get some intermediate data to
> actualize the positions of the objects and then evaluate those
> positions.
> 
> This is the area of the algorith that I think holds the info that I
> need:
> 
> def evolve(self, generations = 100):
>   
> self.halt_reached = 0
>
> for gen in range(generations):
> 
> #Changed.
> print 'GEN:',gen, self.entities
>
> self.do_mutation()
> self.do_crossover()
> print "Average fitness generation " + str(gen) + ": " + 
> str(self.avg_fitness())
> if self.debug == 1:
> self.echo_fitness()
> if self.halt >= 0:
> max_entity = self.get_max_fitness()
> fit = self.calc_fitness(max_entity)
> if fit >= halt:
> self.halt_reached = 1
> return [max_entity]
> 
> The line marked as #Changed is what I changed,  with this I was able
> to print the info, but I'm sorry to say that I have no clue at how to
> apply something like return() that would give me this self.entities
> list. As you can see there is a for loop and I need the info every
> time that it gets updated by the loop.
> 
> Hopefully I'm making myself clear and the info is enough.
> 
> Thanks for your help in advance
> Carlos
> 
> 
> ___
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor


Hi,

when you call return, you return from the function so
when you have something like this:

def loop():
for i in range(10):
return i

print loop()

This will print just 0.

when you want to get all the numbers, you can't use return in the loop
you could save them in a list or something, and after the loop return
the list.

def loop():
x = []
for i in range(10):
x.append(i)
return x

print loop()

this will print a list with all the numbers.

I hope this is what you mean.


Thomas
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] import and unittest

2007-01-16 Thread Thomas Coopman

Hi,

the documentation of pyunit
say that it is good to place the unittest in a seperate module.
I wondered if it was possible to do something like this:

src/
   -a_module/
   -sub_module/
test/
   -a_module/
   -sub_module/

So the test are in a complete different directory than the code and the test
dir is a complete copy
of the src dir but with unittest instead of code.

I have something like this but I don't know how to organize the imports in
the tests and I don't know
if this is a good idea.  What do you think?

Thanks

--
Thomas Coopman
[EMAIL PROTECTED]
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] import and unittest

2007-01-16 Thread thomas coopman
On Tue, 16 Jan 2007 10:06:37 -
"Alan Gauld" <[EMAIL PROTECTED]> wrote:

> 
> "Thomas Coopman" <[EMAIL PROTECTED]> wrote
> .
> > I wondered if it was possible to do something like this:
> >
> > src/
> >-a_module/
> >-sub_module/
> > test/
> >-a_module/
> >-sub_module/
> >
> 
> I don;t see any reason why not although its slightly more work.
> Personally I tend to keep the tests with the code, but thats
> mainly because tools such as editors tend to remember the last
> folder opened and its a pain navigating between the two folders.
> 
> The other system I have used(in C++ not Python) is to have
> a test folder inside each src folder like:
> 
> src/
>mod1/
>f1.py
>test/
>   testf1.py
> mod2/
>f2.py
>f3.py
>test/
>testf1.py
>testf2.py
> 
> etc.
> 
> This minimises navigation and keeps the tests separate.
> Its also relatively easy to filter out the tests when it comes
> time to package upp the code for distribution (assuming
> you want to lose them!)

I think I will use something like this.

> 
> > I have something like this but I don't know how to organize the 
> > imports in
> > the tests and I don't know if this is a good idea.  What do you 
> > think?
> 
> I think in Python you should create a package structure for
> your code so that import can find the modules more easily.
> But I've never tried this in Python, my Python projects are rarely
> big enough to warrant it.
> 
> 
Thanks.
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] import and unittest

2007-01-17 Thread thomas coopman
On Tue, 16 Jan 2007 10:06:37 -
"Alan Gauld" <[EMAIL PROTECTED]> wrote:

> 
> "Thomas Coopman" <[EMAIL PROTECTED]> wrote
> .
> > I wondered if it was possible to do something like this:
> >
> > src/
> >-a_module/
> >-sub_module/
> > test/
> >-a_module/
> >-sub_module/
> >
> 
> I don;t see any reason why not although its slightly more work.
> Personally I tend to keep the tests with the code, but thats
> mainly because tools such as editors tend to remember the last
> folder opened and its a pain navigating between the two folders.
> 
> The other system I have used(in C++ not Python) is to have
> a test folder inside each src folder like:
> 
> src/
>mod1/
>f1.py
>test/
>   testf1.py
> mod2/
>f2.py
>f3.py
>test/
>testf1.py
>testf2.py
> 
> etc.
> 
> This minimises navigation and keeps the tests separate.
> Its also relatively easy to filter out the tests when it comes
> time to package upp the code for distribution (assuming
> you want to lose them!)
> 
> > I have something like this but I don't know how to organize the 
> > imports in
> > the tests and I don't know if this is a good idea.  What do you 
> > think?
> 
> I think in Python you should create a package structure for
> your code so that import can find the modules more easily.
> But I've never tried this in Python, my Python projects are rarely
> big enough to warrant it.
> 
> 

well, I still have problems with import

suppose I have something like this:

M/
  __init__.py
  A/
__init__.py
One.py
  B/
__init__.py
Two.py

One.py
#!/usr/bin/python

from M.B import Two

Two.py
#!/usr/bin/python

from M.A import One


when I try to run One.py or Two.py I get import errors and I don't know
how to fix them.  I tried to set the __all__ variable in the __init__
files but nothing worked so far.

I would like to run the files from anywhere for example.
What am I doing wrong?
I read the information about modules on python.org
(http://www.python.org/doc/2.0.1/tut/node8.html) but I don't find a
solution

Thanks
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] import and unittest

2007-01-17 Thread Thomas Coopman

On 1/17/07, Kent Johnson <[EMAIL PROTECTED]> wrote:


thomas coopman wrote:
> On Tue, 16 Jan 2007 10:06:37 -
> "Alan Gauld" <[EMAIL PROTECTED]> wrote:
>
>> "Thomas Coopman" <[EMAIL PROTECTED]> wrote
>> .
>>> I wondered if it was possible to do something like this:
>>>
>>> src/
>>>-a_module/
>>>-sub_module/
>>> test/
>>>-a_module/
>>>-sub_module/
>>>
>> I don;t see any reason why not although its slightly more work.
>> Personally I tend to keep the tests with the code, but thats
>> mainly because tools such as editors tend to remember the last
>> folder opened and its a pain navigating between the two folders.
>>
>> The other system I have used(in C++ not Python) is to have
>> a test folder inside each src folder like:
>>
>> src/
>>mod1/
>>f1.py
>>test/
>>   testf1.py
>> mod2/
>>f2.py
>>f3.py
>>test/
>>testf1.py
>>testf2.py
>>
>> etc.
>>
>> This minimises navigation and keeps the tests separate.
>> Its also relatively easy to filter out the tests when it comes
>> time to package upp the code for distribution (assuming
>> you want to lose them!)
>>
>>> I have something like this but I don't know how to organize the
>>> imports in
>>> the tests and I don't know if this is a good idea.  What do you
>>> think?
>> I think in Python you should create a package structure for
>> your code so that import can find the modules more easily.
>> But I've never tried this in Python, my Python projects are rarely
>> big enough to warrant it.
>>
>>
>
> well, I still have problems with import
>
> suppose I have something like this:
>
> M/
>   __init__.py
>   A/
> __init__.py
> One.py
>   B/
> __init__.py
> Two.py
>
> One.py
> #!/usr/bin/python
>
> from M.B import Two
>
> Two.py
> #!/usr/bin/python
>
> from M.A import One
>
>
> when I try to run One.py or Two.py I get import errors and I don't know
> how to fix them.  I tried to set the __all__ variable in the __init__
> files but nothing worked so far.

What error do you get?

It's better to avoid this kind of circular import if you can. Rather
than having One depend on Two and Two depend on One, look for some piece
you can factor out into a new module that both One and Two use (or it
may only be needed by One or Two).

There are several problems with circular imports, but the technical
problem you are having is probably like this:

module One starts to execute
One imports Two
Two starts to execute
Two imports One
-- Note that at this point, the body of One has not executed, so
anything defined in One after the import of Two is not yet defined.
Two tries to use something in One. Since One is not fully defined, it
gets an AttributeError.

Anyway, try to split up your modules or post the exact error you get.

Kent



Well I don't really
need the circular imports but I would like to know how to do the
imports correct.
Suppose that in the example that I showed only One needs Two.

So then we have this:

M/
__init__.py
A/
__init__.py
One.py
B/
__init__.py
Two.py

One.py
#!/usr/bin/python

from M.B import Two


when I run this I get this error:
ImportError: No Module named M.B


--
Thomas Coopman
[EMAIL PROTECTED]
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] import and unittest

2007-01-17 Thread Thomas Coopman

On 1/17/07, Kent Johnson <[EMAIL PROTECTED]> wrote:


Thomas Coopman wrote:
> Well I don't really
> need the circular imports but I would like to know how to do the imports
correct.
>
> Suppose that in the example that I showed only One needs Two.
>
> So then we have this:
>
> M/
> __init__.py
> A/
> __init__.py
> One.py
> B/
> __init__.py
> Two.py
>
> One.py
> #!/usr/bin/python
>
> from M.B import Two
>
>
> when I run this I get this error:
> ImportError: No Module named M.B

Is the directory containing M in sys.path?

Kent



When I run One.py from in the directory A, doesn't look python in it's
parent directory when it can't find the module?
And if that's not the case where and what should I add to the sys.pathvariable?


--
Thomas Coopman
[EMAIL PROTECTED]
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] import and unittest

2007-01-17 Thread Thomas Coopman

On 1/17/07, Kent Johnson <[EMAIL PROTECTED]> wrote:


Thomas Coopman wrote:
> When I run One.py from in the directory A, doesn't look python in it's
> parent directory when it can't find the module?
> And if that's not the case where and what should I add to the sys.path
> variable?

No, Python won't look in parent directories for imports. Try running
One.py from the parent dir of M by typing
> python M/A/One.py

or add the parent dir of M to sys.path.

Kent

when I try to run it from the parent dir of M, I still get the error,

where and when should I add the the parent dir to sys.path?

when I try from M.A import One in a shell executed in the parent dir of M
than it works.

The thing is that I would like to run One.py from anywhere and not just from
that one directory.
--
Thomas Coopman
[EMAIL PROTECTED]
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Best IDE for Python

2007-01-26 Thread Mark Thomas
On 1/26/07, OkaMthembo <[EMAIL PROTECTED]> wrote:
> how useable is vim on Windows?

Very! I've used Vim on Windows since the 5.3 version, it only gets
better. Like Alan said there is a learning curve, but once you've "got
it" there is no going back.

> i wish i could learn Unix. which distro do you think is good to learn?

If you just want to have the power of some Unix tools then take a look
at http://gnuwin32.sourceforge.net/ , they all run fine in the
standard Windows shell. If you want to try a Unix variant then find
one of the many "Live" CD's out there which you can use before you
slice up your disk. I'm a big fan of NetBSD but at the moment I'm
running OpenBSD 4.0 on my PIII laptop and it's very nice.

-- 
()  ascii ribbon campaign - against html e-mail
/\  www.asciiribbon.org   - against proprietary attachments
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] comparing almost equal strings

2007-02-08 Thread thomas coopman
Hi,

I need a function that groups almost equal strings.  It seems most easy
to me, to do this with a hash function.

So I would write a hash function like this:
string = string.replace(" ", "").lower()[0:6]

and then hash the string chars, but it should detect minor typo's, so
words with one different char in the 6 chars, should have the same hash.

I think I once read something about it, but I can't find it, 
does somebody know how to do this?

Also do you think this is a good way, or do some of you have experience
with this and know a better way?

Thanks
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] comparing almost equal strings

2007-02-08 Thread thomas coopman
Hi,

On Thu, 08 Feb
2007 13:07:41 +0100
Christopher Arndt <[EMAIL PROTECTED]> wrote:

> thomas coopman schrieb:
> > I need a function that groups almost equal strings.  It seems most
> > easy to me, to do this with a hash function.
> 
> What do you mean be "almost equal"? By which criterium? Spelling,
> Pronounciation? Semantics?
> 
> > I think I once read something about it, but I can't find it, 
> > does somebody know how to do this?
> 
> Maybe you mean the "soundex" algorithm? See, for example, here:
> 
> http://diveintopython.org/performance_tuning/index.html

This is what I was looking for!
> 
> Chris
> ___
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor

Thanks!

Thomas
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] class methods as argument

2007-02-10 Thread thomas coopman
Hi,

I want to do something like this, don't know how to properly explain it,
so I just give you some example code

>>>class Foo(object):
>>> def method(self, arg):
>>> print arg

>>>def doSomething(object, func):
>>> object.func("test")

>>>object = Foo()
>>>doSomething(object, Foo.method)

I want to execute the class method given as argument,
but this obvious doesn't work, but I don't know how to
get it work,
Is it possible?
and how?

Thanks

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] class methods as argument

2007-02-10 Thread thomas coopman
On Sat, 10 Feb 2007 22:10:52 +1000
Jonathan McManus <[EMAIL PROTECTED]> wrote:

> It's pretty easy to make this work, actually. The issue is in the
> "doSomething" method.
> 
> > >>>class Foo(object):
> > >>> def method(self, arg):
> > >>> print arg
> > 
> > >>>def doSomething(object, func):
> > >>> object.func("test")
> 
> Here, it's looking for a method of the "Foo" object (object) called
> "func" (AttributeError: 'Foo' object has no attribute 'func'), instead
> of replacing "func" with "Foo.method". 
> 
> What you need to do is:
> 
> >>> def doSomething (object, func):
> >>>   func(object, "test")
> 
> This means that you are calling the method (explicity passed as being
> a method of Foo), as well as supplying the actual object as the first
> argument (the required self for classes).
> 
> >>> object = Foo()
> >>> doSomething(object, Foo.method)
> test
> 
> Hope that helps.
> 


Thanks,
that I've didn't come up with that myself!
It's indeed easy!
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] class methods as argument

2007-02-10 Thread thomas coopman
On Sat, 10 Feb 2007 07:55:54 -0500
Kent Johnson <[EMAIL PROTECTED]> wrote:

> thomas coopman wrote:
> > Hi,
> > 
> > I want to do something like this, don't know how to properly
> > explain it, so I just give you some example code
> > 
> >>>> class Foo(object):
> >>>>  def method(self, arg):
> >>>>  print arg
> > 
> >>>> def doSomething(object, func):
> >>>>  object.func("test")
> > 
> >>>> object = Foo()
> >>>> doSomething(object, Foo.method)
> > 
> > I want to execute the class method given as argument,
> > but this obvious doesn't work, but I don't know how to
> > get it work,
> 
> First a quick note - don't use object as a parameter or variable
> name, it will hide the definition of the built-in object class.
Yes, I know, it was a bad example
> 
> You are very close. Foo.method is called an 'unbound method' of class 
> Foo. The syntax for calling an unbound method is to pass a class 
> instance as the first argument, followed by the actual argument list.
> It is actually the same argument list that you use when you declare
> the function (starting with self).
> 
> So your example can be written this way:
> 
> In [4]: class Foo(object):
> ...: def method(self, arg):
> ...: print arg
> 
> In [6]: o=Foo()
> 
> In [8]: def doSomething(obj, func):
> ...: func(obj, "test")
> 
> In [9]: doSomething(o, Foo.method)
> test
> 
> 
> A more common way to do this is to use a 'bound method'. That is what 
> you get when you refer to instance.method instead of Class.method. A 
> bound method includes a reference to the particular instance and can
> be called like an ordinary function. Rather than passing the instance
> and the unbound method to doSomething(), just pass the bound method
> as a single argument:
> 

> In [10]: def doSomething(func):
> : func("test")
> 
> In [12]: doSomething(o.method)
> test
> 
> In summary:
> Class.method => unbound method, call with instance as first arg
> instance.method => bound method, call with normal argument list
> 
> Kent
> 

Thank you for the explanation of bound and unbound methods.
I understand that it is more common to use a bound method, but I don't
think that I can use this because at the time I save the method, I don't
know anything about the instances.

I use this for making a sorted list using any method you give as
argument when you create the list.  This class only gets to know it's
instances when you add them.

In [3]: class SortedList(object):
   ...: def __init__(self, compare):
   ...: self.compare = compare
   ...: def __add_(self, object):
   ...:     for i in self.data:
   ...: self.compare(object, i)
   ...:

In [4]: class FooList(SortedList):
   ...: def __init__(self):
   ...: self.compare = Foo.compare


__add__ doesn't do anything here of course, it is just an example,
but I don't think that I can use a bound method in this case?

also,
Is it better to use super in FooList? and how should I use it then?

Thomas
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] class methods as argument

2007-02-10 Thread thomas coopman
On Sat, 10 Feb 2007 09:04:15 -0500
Kent Johnson <[EMAIL PROTECTED]> wrote:

> thomas coopman wrote:
> > 
> > also,
> > Is it better to use super in FooList? and how should I use it then?
> 
> Actually I would say that FooList is not pulling its weight.
> SortedList already allows specialization by the compare function, so
> to create the equivalent of a FooList you just call
> SortedList(Foo.compare).
I know that in this example it's rather useless to create FooList, but
the subclasses I have of SortedList have other specializations so I
will keep using them.

> 
> If you do want to keep FooList then you should call 
> SortedList.__init__() to set the compare function.
> SortedList.__init__ is an unbound function so you call it like this:
>SortedList.__init__(self, Foo.compare)
This works.
I think I'll need to reed some more about super because I thought I had
to use super in this case.

> 
> Another design you might want to consider - if you will always be 
> sorting each type of list by the same compare method - is to define a 
> __cmp__() method in each class that will be part of a SortedList and
> use plain comparison operators (< > etc) to do the compare.
That's the problem.  I define for most of my classes a __cmp__() method
but, some classes have another way of being sorted, and that's why I
give the compare method as an argument in SortedList

> 
> Finally note that Python's sort() function is very fast and flexible
> and it might be better just to sort the list when you need it to be
> sorted, rather than keeping it sorted. Or maybe what you really need
> is a heap (see the heapq module). If you really want to keep a sorted
> list, you should look at the bisect module, it might help.
I now use sort() when there is some data initially.  After creation, I
insert data with my own bisect method, I also use it to search the data.

I mostly need the sorted list, because I want to detect when a object
is added with the same value of some item in the list and take
appropriate actions.

> 
> Kent
> 

Thomas
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Open a directory in the default file manager

2008-05-16 Thread Thomas Pani

Tim Michelsen wrote:
> Hello,
> is there any function/module that allows me to open a directory in the
> default file manager of a operating system?

On Windows you can use os.startfile().
On "pure" Unices there's no such thing as filetype associations
However, if you use a desktop environment, you can spawn xdg-open (from 
xdg-utils) from Python. This will autodetect gnome, kde and xfce and use 
their tools (gnome-open, kfmclient, exo-open).

I think on OS X/Darwin there's a similar utility called `open'.

You can use sys.platform to determine which system you're running on.

thomas
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] listing classes

2008-05-20 Thread Thomas Pani

Hi,

dir(A) will essentially give you what you want (and a little more)

If you're only interested in classes, you can do something like:

import types
[ name for name in dir(A) if type(eval('A.'+name)) == types.ClassType ]

Thomas

Laureano Arcanio wrote:

Hi All,

I need to have a listing of all classes defined inside a class body,
something like this:

class A(object):
class B(object):
pass
class C(object):
pass(object):

and i need to get the classes to instantiate them.. something like this.

classes =[A,B]

Any ideas ? do i need meta classes or something ?

Thanks in advice.





___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Unable to Reconfigure IDLE

2008-07-26 Thread Thomas Corbett

Running IDLE 1.2.2 under MacPython 2.5 on Mac OS X 5.1.

Configured shell window to wrong size, now can't seem to find the menu  
(Options > Configure) to resize the shell.


Tried going to username > Library > Preferences  and removing  
org.python* files, but that did not work.


Thanks!
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Unable to Reconfigure IDLE

2008-07-26 Thread Thomas Corbett


On Jul 26, 2008, at 9:02 AM, Alan Gauld wrote:



"Thomas Corbett" <[EMAIL PROTECTED]> wrote

Configured shell window to wrong size, now can't seem to find the  
menu  (Options > Configure) to resize the shell.


Don't you just resize it then close it and the next time it opens
it uses the new size?

Thats how I thought it was supposed to work!

Alan G

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor



The window is too large to resize.

-Tom

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Unable to Reconfigure IDLE

2008-07-28 Thread Thomas Corbett


On Jul 27, 2008, at 7:16 AM, Tim Golden wrote:


Thomas Corbett wrote:

On Jul 26, 2008, at 9:02 AM, Alan Gauld wrote:


"Thomas Corbett" <[EMAIL PROTECTED]> wrote

Configured shell window to wrong size, now can't seem to find the  
menu  (Options > Configure) to resize the shell.


Don't you just resize it then close it and the next time it opens
it uses the new size?

Thats how I thought it was supposed to work!

Alan G

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor

The window is too large to resize.


I missed the beginning of this thread, but I assume that you
mean its edges are off the visible screen so you can't use
the mouse to grab the frame and resize it? If so, and if
you're on Windows, you can resize with the keyboard:
Alt-Space S will put you in Sizing mode; then use the
cursor keys to move the edges in and out. Alternatively,
Alt -Space M will put the window in Moving mode and, again,
the cursor keys can be used to bring a corner into view
and into range of the mouse.

TJG

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Running IDLE 1.2.2 under MacPython 2.5 on Mac OS X 5.1. Not aware of a  
similar option on Mac.


___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Decimals 'not equal to themselves' (e.g. 0.2 equals 0.200000001)

2008-08-03 Thread Thomas Pani

CNiall wrote:
I want to make a simple script that calculates the n-th root of a given 
number (e.g. 4th root of 625--obviously five, but it's just an example 
:P), and because there is no nth-root function in Python I will do this 
with something like x**(1/n).


Side note: of course there are python built-in ways to do that. You just 
named one yourself:


In [6]: 625**(1.0/4)
Out[6]: 5.0

also:

In [9]: pow(625, 1.0/4)
Out[9]: 5.0

However, with some, but not all, decimals, they do not seem to 'equal 
themselves'.


As you can see, the last two decimals are very slightly inaccurate. 
However, it appears that when n in 1/n is a power of two, the decimal 
does not get 'thrown off'. How might I make Python recognise 0.2 as 0.2 
and not 0.20001?



You just can't store 0.1 as a binary floating point.
You might want to read:
http://www.network-theory.co.uk/docs/pytut/FloatingPointArithmeticIssuesandLimitations.html
http://www.network-theory.co.uk/docs/pytut/RepresentationError.html

The decimal module provides decimal floating point arithmetic:
http://docs.python.org/lib/module-decimal.html

like in:
In [1]: 0.2 * 2
Out[1]: 0.40002

In [2]: from decimal import Decimal

In [3]: Decimal('0.2') * 2
Out[3]: Decimal("0.4")

thomas
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] XML to text

2008-10-24 Thread Thomas Walch

This might be helpful:

http://www.boddie.org.uk/python/XML_intro.html

Have fun!

Thomas

Dinesh B Vadhia schrieb:
I have a large number of xml files that I want to convert into text 
format.  What is the best and easiest way to do this?  Thanks!
 
Dinesh
 



___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor
  

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Testing dymamically created methods

2012-01-10 Thread Thomas Maier
Hi all,

I would like to use some existing tool like py.test or nose to
run my tests, but I failed to do so.
The problem is as follow. I have tests:

### test_methods.py ###
def test_one():
assert 1 == 1

def test_two():
assert 1 == 1

#

I have abstraction layer that keeps information
about this test, like method name.
It's simple JSON file.

Then I have the test runner:

### test_runner.py ###
def read_test_definition():
   """read the JSON file and returns dict with test details"""

def test_run():
   my_test_data = read_test_definition()
   import test_methods
   for testid in my_test_data:
   my_method = my_test_data[testid]
   # here the 'my_method' is equal 'test_one' or 'test_two', hope
it's clear..
   test_method = getattr(test_methods, my_method)
   test_method()

###

This code works without py.test or nosetests. For example if I use print
instead of 'assert'.
Both py.test and nosetests failed to execute this correctly.
Or maybe they do execute it correctly, I just don't understand it..:)
They both report only single test was executed.
I would like to see test report for each method executed in 'for' loop.
Is it possible?

PS. Sorry for my ignorance, I just started to learn Python last week.

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


Re: [Tutor] Testing dymamically created methods

2012-01-10 Thread Thomas Maier
On Tue, Jan 10, 2012 at 3:31 PM, Walter Prins  wrote:
> Hi,
>
> On 10 January 2012 12:15, Thomas Maier  wrote:
>> This code works without py.test or nosetests. For example if I use print
>> instead of 'assert'.
>> Both py.test and nosetests failed to execute this correctly.
>> Or maybe they do execute it correctly, I just don't understand it..:)
>> They both report only single test was executed.
>> I would like to see test report for each method executed in 'for' loop.
>> Is it possible?
>
> For nose, I *think* you can basically achieve what you want by turning
> test_run() into a generator (by essentially replacing the call to the
> test_method() with a suitable "yield" statement.   See here:
> http://readthedocs.org/docs/nose/en/latest/writing_tests.html#test-generators
Works perfect.

> Additionally you might also look at the TestLoader functionality for
> taking further control over how and where your tests are loaded, e.g.
> see for example nose.loader.loadTestsFromGenerator() or
> nose.loader.loadTestsFromGeneratorMethod() (or indeed all the other
> methods) here:
> http://readthedocs.org/docs/nose/en/latest/api/loader.html
Will try later.

> HTH, my $0.02 worth,
>
> Walter

Thank you very much!

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


Re: [Tutor] creating dict of dict : similar to perl hash of hash

2012-03-06 Thread Thomas Maier
On Tue, Mar 6, 2012 at 8:19 PM, David Rock  wrote:
> * Abhishek Pratap  [2012-03-06 09:50]:
>> Hi Guys
>>
>> I am looking for a way to build dictionaries of dict in python.
>>
>> For example in perl I could do
>>
>> my $hash_ref = {};
>> $hash->{$a}->{$b}->{$c} = "value";
>> if (exists $hash->{$a}->{$b}->{$c} ){ print "found value"}
>>
>> Can I do something similar with dictionaries in Python.
>
> Absolutely.  Python is very good at using nested dicts.
>
> dict = {}
> dict['a'] ={}
> dict['a']['b'] = {}
> dict['a']['b']['c']= "value"
>
>
> This is a bit brute force, but it illustrates that the intermediary keys
> need to exist.  ie, if you try to assign directly, it won't work:
>
> Type "help", "copyright", "credits" or "license" for more information.
>>>> dict ={}
>>>> dict['a']['b']['c'] = 'value'
> Traceback (most recent call last):
>  File "", line 1, in 
>  KeyError: 'a'
>
> Since the key 'a' doesn't exist, it throws an exception.
>
> Python is also more flexible than perl in nesting data because it
> doesn't have to be the same data type.  You can nest variables, lists,
> dicts, etc all at the same level:
>
> dict = {}
> dict['mylist'] = [1,2,3]
> dict['mystring'] = 'string'
> dict['mynum'] = 4
> dict['anotherdict'] = {}
> dict['anotherdict']['anotherstring'] = 'string2'
>
Hi David,
Mixed data types in nested data structure are possible in Perl as well:
%hash = ();
$hash{'mylist'} = [1,2,3];
$hash{'mystring'} = 'string';
$hash{'mynum'} = 4;
$hash{'anotherhash'} = {};
$hash{'anotherhash'}{'anotherstring'} = 'string2';

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


[Tutor] How do you save work in progress in Pyscripter ?

2012-04-06 Thread Thomas Mujica
Please help a newbie

 

Was able to write and successfully run this but I can't seem to be able to
"save" it

 

Luckily I had saved it to Word and then I was able to copy and paste it back
into PyScripter.

 

I'm using 

 

Python Scripter Version 2.5.3.0 x86

 

*** Python 2.7.2 (default, Jun 12 2011, 15:08:59) [MSC v.1500 32 bit
(Intel)] on win32. ***

*** Remote Python engine  is active ***

>>> 

 

>>> from decimal import *

>>> getcontext()

Context(prec=28, rounding=ROUND_HALF_EVEN, Emin=-9, Emax=9,
capitals=1, flags=[], traps=[DivisionByZero, InvalidOperation, Overflow])

>>> getcontext().prec=3#change decimal precision to 3
decimal places

>>> for a in xrange(1,30): #NESTED   note no matter what the variables are
the syntax is always xrange

... for b in xrange(1,30): #LOOPS DO 29 ITERATIONS

... c=pow(a,2)+pow(b,2)# this is really c squared
because a and b are raised to exponent 2

... h=pow(c,.5)   #pow is .5 so h is the
square root of c ...h is the hypotenuse

... d=round(h,2)

... if a==1 and b==1: #will allow titles to be
printed at beginning of print out

... print "Side a","Side b","Hypotenuse"

... if h==d and d==h:#will eliminate all values of h
that are not integers from printout

... print"  ",a,"\t",b,"\t\t",h  #for alignment purpose "3
spaces " before a then tab b, and 2tabs   ...
# before h

 

 

 

Side a Side b Hypotenuse

3  4  5.0

4  3  5.0

5  1213.0

6  8  10.0

7  2425.0

8  6  10.0

8  1517.0

9  1215.0

102426.0

125  13.0

129  15.0

121620.0

158  17.0

152025.0

161220.0

182430.0

201525.0

202129.0

212029.0

212835.0

247  25.0

241026.0

241830.0

282135.0

 

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


[Tutor] tkinter in Python 3

2015-08-27 Thread Michael Thomas
I'm trying to move a Python 2.x program to Python 3.x. When I try to import
tkinter I get the error message that no module _tkinter can be found. I've
tried sudo apt-get install python-tk. While this command works, there is no
difference in the result. This problem has only cropped up after I changed
to Ubuntu 15.04. Does anyone have any suggestions?
Thanks in advance for any help.
Mike
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


[Tutor] Issue with Code

2016-04-30 Thread Olaoluwa Thomas
Hi, I'm new to Python and programming in general. I came across a simple
exercise that is used to compute gross pay when prompted to enter number of
hours and hourly rate.

I've attached the scripts in question (created via Notepad++).
The 1st script I wrote worked perfectly.

The 2nd script makes amendments to the 1st by increasing the hourly rate by
50% when number of hours is greater than 40.
The problem with this script is that the "else" statement (which is
equivalent to the 1st script) does not compute gross pay accurately as seen
in the attached screenshot.

I would appreciate a logical explanation for why the "else" statement in
the 2nd script isn't working properly.

I'm running Python v2.7.8 on a Windows 7 Ultimate VM via Command prompt and
my scripts are created and edited via Notepad++ v6.7.3

*Warm regards,*

*Olaoluwa O. Thomas,*
*+2347068392705*
hours = raw_input ('How many hours do you work?\n')
rate = raw_input ('What is your hourly rate?\n')
gross = float(hours) * float(rate)
print "Your Gross pay is "+str(round(gross, 4))hours = raw_input ('How many hours do you work?\n')
rate = raw_input ('What is your hourly rate?\n')
if hours > 40:
gross = ((float(hours) - 40) * (float(rate) * 1.5)) + (40 * float(rate)) 
else:
gross = float(hours) * float(rate)
print "Your Gross pay is "+str(round(gross, 4))___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


[Tutor] Fwd: Issue with Code

2016-04-30 Thread Olaoluwa Thomas
Hi All,

I sent this forwarded email earlier but hadn't subscribed to the mailing
list so I guess that's why I didn't get a response.

Please review and advise.

*Warm regards,*

*Olaoluwa O. Thomas,*
*+2347068392705*

-- Forwarded message --
From: Olaoluwa Thomas 
Date: Sat, Apr 30, 2016 at 4:30 PM
Subject: Issue with Code
To: tutor@python.org


Hi, I'm new to Python and programming in general. I came across a simple
exercise that is used to compute gross pay when prompted to enter number of
hours and hourly rate.

I've attached the scripts in question (created via Notepad++).
The 1st script I wrote worked perfectly.

The 2nd script makes amendments to the 1st by increasing the hourly rate by
50% when number of hours is greater than 40.
The problem with this script is that the "else" statement (which is
equivalent to the 1st script) does not compute gross pay accurately as seen
in the attached screenshot.

I would appreciate a logical explanation for why the "else" statement in
the 2nd script isn't working properly.

I'm running Python v2.7.8 on a Windows 7 Ultimate VM via Command prompt and
my scripts are created and edited via Notepad++ v6.7.3

*Warm regards,*

*Olaoluwa O. Thomas,*
*+2347068392705*
hours = raw_input ('How many hours do you work?\n')
rate = raw_input ('What is your hourly rate?\n')
gross = float(hours) * float(rate)
print "Your Gross pay is "+str(round(gross, 4))hours = raw_input ('How many hours do you work?\n')
rate = raw_input ('What is your hourly rate?\n')
if hours > 40:
gross = ((float(hours) - 40) * (float(rate) * 1.5)) + (40 * float(rate)) 
else:
gross = float(hours) * float(rate)
print "Your Gross pay is "+str(round(gross, 4))___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Issue with Code [SOLVED]

2016-04-30 Thread Olaoluwa Thomas
Thank you so much, Alan. That fixed it (See Script 2[SOLVED] below).

For the purpose of record-keeping, I'm pasting the entire code of all
scripts below as I should have done from the very beginning.

P.S. How were you able to open attachments with the restrictions on this
mailing list?

Script 1
hours = raw_input ('How many hours do you work?\n')
rate = raw_input ('What is your hourly rate?\n')
gross = float(hours) * float(rate)
print "Your Gross pay is "+str(round(gross, 4))

Script 2
hours = raw_input ('How many hours do you work?\n')
rate = raw_input ('What is your hourly rate?\n')
if hours > 40:
gross = ((float(hours) - 40) * (float(rate) * 1.5)) + (40 * float(rate))
elif hours >= 0 and hours <= 40:
gross = float(hours) * float(rate)
print "Your Gross pay is "+str(round(gross, 4))

Script 2 [SOLVED]
hours = float(raw_input ('How many hours do you work?\n'))
rate = float(raw_input ('What is your hourly rate?\n'))
if hours > 40:
gross = ((hours - 40) * (rate * 1.5)) + (40 * rate)
elif hours >= 0 and hours <= 40:
gross = hours * rate
print "Your Gross pay is "+str(round(gross, 4))

I'm gonna add Try and Except to make it more responsive.

Thanks a lot!

*Warm regards,*

*Olaoluwa O. Thomas,*
*+2347068392705*

On Sun, May 1, 2016 at 2:00 AM, Alan Gauld via Tutor 
wrote:

> On 01/05/16 01:16, Alan Gauld via Tutor wrote:
>
> > I can't see anything obviously wrong in your code
>
> I was too busy focusing on the calculations that
> I didn't check the 'if' test closely enough.
> You need to convert your values from strings
> before comparing them.
>
> hours = float(raw_input ('How many hours do you work?\n'))
> rate = float(raw_input ('What is your hourly rate?\n'))
> if hours > 40:
>gross = (hours-40)*(rate*1.5) + (rate*40)
> else:
>gross = hours*rate
>
>
> Sorry,
>
> --
> Alan G
> Author of the Learn to Program web site
> http://www.alan-g.me.uk/
> http://www.amazon.com/author/alan_gauld
> Follow my photo-blog on Flickr at:
> http://www.flickr.com/photos/alangauldphotos
>
>
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


[Tutor] Issues converting a script to a functioin (or something)

2016-05-01 Thread Olaoluwa Thomas
The novice Python programmer is back.

I'm trying to incorporate a function and its call in the GrossPay.py script
that Alan solved for me.
It computes total pay based on two inputs, no. of hours and hourly rate.

There's a computation for overtime payments in the if statement.

Something seems to be broken.

Here's the code:
def computepay(hours, rate):
hours = float(raw_input ('How many hours do you work?\n'))
rate = float(raw_input ('What is your hourly rate?\n'))
if hours > 40:
gross = ((hours - 40) * (rate * 1.5)) + (40 * rate)
elif hours >= 0 and hours <= 40:
gross = hours * rate
print "Your Gross pay is "+str(round(gross, 4))

computepay()

What am I doing wrong?

*Warm regards,*

*Olaoluwa O. Thomas,*
*+2347068392705*
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Issues converting a script to a functioin (or something) [SOLVED]

2016-05-01 Thread Olaoluwa Thomas
Hi Bob,

Thanks for your feedback. Please do not hesitate to provide more as I shall
email you personally in the future.

The script is made up of a function definition and its call prompting the
user for input.

The script itself takes "number of hours worked" and "hourly rate" as
inputs and gives gross pay as a product of the two.
As I stated in my earlier email, there is also a portion for calculating
gross pay with considerations for overtime (> 40 hours worked).

The problem was that running the code gave an error which I now do not
remember in detail as I have moved on after having fixed it.

Here's the initial email below with Sreenathan's helpful input followed by
my amendments to the code:
(I thought my initial email was quite self-explanatory but what do I
know... Please read through to the end)

On Sun, May 1, 2016 at 1:09 PM, Sreenathan Nair 
 wrote:

> On Sun, May 01, 2016 at 5:34 PM, Olaoluwa Thomas 
> wrote:
>
> The novice Python programmer is back.
>
> I'm trying to incorporate a function and its call in the GrossPay.py
> script
> that Alan solved for me.
> It computes total pay based on two inputs, no. of hours and hourly rate.
>
> There's a computation for overtime payments in the if statement.
>
> Something seems to be broken.
>
> Here's the code:
> def computepay(hours, rate):
> hours = float(raw_input ('How many hours do you work?\n'))
> rate = float(raw_input ('What is your hourly rate?\n'))
> if hours > 40:
> gross = ((hours - 40) * (rate * 1.5)) + (40 * rate)
> elif hours >= 0 and hours <= 40:
> gross = hours * rate
> print "Your Gross pay is "+str(round(gross, 4))
>
> computepay()
>
> What am I doing wrong?
>
> *Warm regards,*
>
> *Olaoluwa O. Thomas,*
> *+2347068392705*
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor
>
>  Hi,
> The parameters hours and rate are required when calling the method
> computepay ex: computepay(8, 200), so basically computepay() by itself will
> throw an error  Also, as a suggestion if you're gonna get hours and
> rate via user input perhaps they can be removed from the method definition?
>
> ​Thanks, Sreenathan. These alterations solved it.

def computepay(hours, rate):
if hours > 40:
gross = ((hours - 40) * (rate * 1.5)) + (40 * rate)
elif hours >= 0 and hours <= 40:
    gross = hours * rate
print "Your Gross pay is "+str(round(gross, 4))
computepay(hours = float(raw_input ('How many hours do you work?\n')), rate
= float(raw_input ('What is your hourly rate?\n')))

*Warm regards,*

*Olaoluwa O. Thomas,*
*+2347068392705*

On Sun, May 1, 2016 at 2:13 PM, Bob Gailer  wrote:

>
> On May 1, 2016 8:04 AM, "Olaoluwa Thomas" 
> wrote:
> >
> > The novice Python programmer is back.
> Welcome back. We are here to help you when you are stuck. Telling us
> something is broken is not adequate. Tell us-what you are expecting the
> program to do and what results you're getting.
> >
> > I'm trying to incorporate a function and its call in the GrossPay.py
> script
> > that Alan solved for me.
> > It computes total pay based on two inputs, no. of hours and hourly rate.
> >
> > There's a computation for overtime payments in the if statement.
> >
> > Something seems to be broken.
> >
> > Here's the code:
> > def computepay(hours, rate):
> > hours = float(raw_input ('How many hours do you work?\n'))
> > rate = float(raw_input ('What is your hourly rate?\n'))
> > if hours > 40:
> > gross = ((hours - 40) * (rate * 1.5)) + (40 * rate)
> > elif hours >= 0 and hours <= 40:
> > gross = hours * rate
> > print "Your Gross pay is "+str(round(gross, 4))
> >
> > computepay()
> >
> > What am I doing wrong?
> >
> > *Warm regards,*
> >
> > *Olaoluwa O. Thomas,*
> > *+2347068392705*
> > ___
> > Tutor maillist  -  Tutor@python.org
> > To unsubscribe or change subscription options:
> > https://mail.python.org/mailman/listinfo/tutor
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Issues converting a script to a functioin (or something) [SOLVED]

2016-05-01 Thread Olaoluwa Thomas
Gotcha.

*Warm regards,*

*Olaoluwa O. Thomas,*
*+2347068392705*

On Sun, May 1, 2016 at 7:14 PM, Alan Gauld via Tutor 
wrote:

> On 01/05/16 14:38, Olaoluwa Thomas wrote:
>
> > Thanks for your feedback. Please do not hesitate to provide more as I
> shall
> > email you personally in the future.
>
> Please don't do that.
> a) Bob is a busy man who volunteers his time here, but may
>have other things to do too.
> b) The list is here so that everyone can benefit from the
>discussions not only the people actively involved.
>
>
> > The problem was that running the code gave an error which I now do not
> > remember in detail as I have moved on after having fixed it.
>
> But the answer is nearly always in the detail. And as you get
> more advanced in coding the errors get harder to spot. That's
> why it is important to supply us (or any other forum) with
> as much detail as you can.
>
>
> --
> Alan G
> Author of the Learn to Program web site
> http://www.alan-g.me.uk/
> http://www.amazon.com/author/alan_gauld
> Follow my photo-blog on Flickr at:
> http://www.flickr.com/photos/alangauldphotos
>
>
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


[Tutor] Semantic Error: Trying to access elements of list and append to empty list with for loop

2016-06-02 Thread Olaoluwa Thomas
Hi Tutor,

I'm trying to parse words in a file line by line and place all words into
another list but I keep getting a list with nested lists.
I would normally pore over it and go to google and fix my problems but this
one escapes me and frankly, I'm tired of being stuck in the same place for
almost a week.

Here's the code:
fname = raw_input('Enter file name:\n')
try:
fhand = open(fname)
except:
print 'File cannot be found or opened:', fname
exit()
lst = list()
for line in fhand:
words = line.split()
#print words (this was a test that a portion of my code was working)
lst.append(words)
print lst

A text file with the following contents
"But soft
what light through yonder window breaks
It is the east and Juliet is the sun
Arise fair sun and kill the envious moon
Who is already sick and pale with grief"

would give me the output in the attached screenshot
[image: Inline image 2]

whereas I want only one list containing strings not nested lists.

Any help would be appreciated.

*Warm regards,*

*Olaoluwa O. Thomas,*
*+2347068392705*
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Semantic Error: Trying to access elements of list and append to empty list with for loop

2016-06-02 Thread Olaoluwa Thomas
Thanks, everyone, for your help.

The objective was to extract all words from each line and place them in a
list IF they didn't already exist in it.
I sorted it out by adding little bits of everyone's suggestions.

Here's the code that fixed it.

fname = raw_input('Enter file name:\n')
try:
fhand = open(fname)
except:
print 'File cannot be found or opened:', fname
exit()
lst = list()
for line in fhand:
words = line.split()
for word in words:
if word in lst:
continue
else:
lst.append(word)
lst.sort()
print lst

I named the file WordExtract.py since it does just that. :)

*Warm regards,*

*Olaoluwa O. Thomas,*
*+2347068392705*

On Thu, Jun 2, 2016 at 6:44 PM, Steven D'Aprano  wrote:

> On Thu, Jun 02, 2016 at 06:05:43PM +0100, Olaoluwa Thomas wrote:
>
> > fname = raw_input('Enter file name:\n')
> > try:
> > fhand = open(fname)
> > except:
> > print 'File cannot be found or opened:', fname
> > exit()
> > lst = list()
> > for line in fhand:
> > words = line.split()
> > #print words (this was a test that a portion of my code was working)
> > lst.append(words)
>
> If you printed words, you should have seen that it was a list.
>
> If you append a list to a list, what do you get? At the interactive
> prompt, try it:
>
>
> py> L = [1, 2, 3]
> py> L.append([4, 5, 6])
> py> L
> [1, 2, 3, [4, 5, 6]]
>
>
> Append takes a single argument, and adds it *unchanged* to the end of
> the list.
>
> What you want is the extend method. It takes a list as argument, and
> appends each item individually:
>
>
> py> L.extend([7, 8, 9])
> py> L
> [1, 2, 3, [4, 5, 6], 7, 8, 9]
>
>
> But if you didn't know about that, you could have done it the
> old-fashioned way:
>
> lst = list()
> for line in fhand:
> words = line.split()
> for word in words:
> lst.append(word)
>
>
>
> --
> Steve
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


[Tutor] NumPy and SciPy

2016-09-27 Thread Floeck, Thomas
Hi there,

you have an idea where I can find NumPy and SciPy windows *.exe-files for 
Python 3.5?

Thanks for any help!


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


[Tutor] Which version of python should i use?

2013-05-20 Thread Amal Thomas
hi,
   I am a beginner. I am using a unix sytem (ubuntu 12.10). Python 2.7.3
is installed in my system. I found out that Python has version upto 3.3.2.
Should I update my python version? Is the syntaxes of the each version
different?

Thanks,

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


Re: [Tutor] Which version of python should i use?

2013-05-20 Thread Amal Thomas
Thank you very much..!! I am starting to learn python for my Bioinformatics
work, so I would look for the version that has libraries helpful for me..


On Mon, May 20, 2013 at 6:38 PM, Dave Angel  wrote:

> On 05/20/2013 05:59 AM, Amal Thomas wrote:
>
>> hi,
>> I am a beginner. I am using a unix sytem (ubuntu 12.10). Python 2.7.3
>> is installed in my system. I found out that Python has version upto 3.3.2.
>>
>
> Welcome, and thanks for telling us your environment up front.
>
>
>
>  Should I update my python version?
>>
>
> No.  Your OS has lots of dependencies on that installed Python, and if you
> remove that one (eg. replace it), many things will stop working.
>
> HOWEVER, you can install a second Python, of whatever version, and use
> that for all your own experimenting and learning.  So the question is which
> one you should use for learning.  My comments at the end.
>
>
>  Is the syntaxes of the each version
>> different?
>>
>>
> Yes.  Not only syntax but semantics as well.  Version 3.0 was deliberately
> a breaking update, where many of the painful gotchas in the language were
> fixed, even if it meant things were incompatible.  There is a 2to3 utility,
> but the transition can be painful for large programs.
>
> Which one should you learn on?
>
> #1 --- if you're committed to a particular tutorial, use the version that
> matches the tutorial.  At your stage, you don't want to have to convert
> every example in your head before getting it to work.
>
> #2 --- If you have a particular library or libraries that you plan to use,
> and it's only currently available for one version, then use that version.
>
> #3 --- If neither of the above apply, then use 3.3 or the soon-coming 3.4.
>
> What's different?  For a beginner, the most noticeable different is that
> the print statement in 2.x was replaced by a print function in 3.x  For
> really simple cases, that just means slap a parentheses around the
> argument(s).  But the print statement has syntax for redirecting to a file,
> while the print function has a parameter.  And the technique for
> suppressing the trailing newline is different.  Etc.
>
> The second most noticeable difference is that 3.x handles Unicode
> directly, so that a string is Unicode, and if you want bytes, those are
> different.
>
>
>
>
> --
> DaveA
>
> __**_
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/**mailman/listinfo/tutor<http://mail.python.org/mailman/listinfo/tutor>
>



-- 
*AMAL THOMAS
Third Year Undergraduate Student
Department of Biotechnology
IIT KHARAGPUR-721302*
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Random Number Game: Returns always the same number - why?

2013-05-20 Thread Thomas Murphy
Mitya,
Why is it best in this situation to use range() rather than a while
loop? Curious about best practices for the various iterating
functions. Thanks!


> There are a few issues here:
> * variable names should be lower case
> * for this case it's best to use for loop with range()
> * you calculate random number only once, outside of loop
>
> Try something like:
>
> for count in range(100):
> print random.randint(1, 100)
>
>
> -m
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Load Entire File into memory

2013-11-04 Thread Amal Thomas
Hi,

 I am new to python. I am working in computational biology and I have to
deal with text files of huge size. I know how to read line by line from a
text file. I want to know the best method in  *python3* to load the enire
file into ram and do the operations.(since this saves time)
  I am currently using this method to load my text file:


*f = open("output.txt")content=io.StringIO(f.read())f.close()*
 But I have found that this method uses 4 times the size of text file.( if
output.txt is 1 gb total ram usage of the code is approx 3.5 gb :( ).
Kindly suggest me a better way to do this.

Working on
Python 3.3.1,ubuntu 13.04(Linux  3.8.0-29-generic x64)

Thanks

-- 


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


Re: [Tutor] Load Entire File into memory

2013-11-04 Thread Amal Thomas
Hi,

Thanks Alan.

Now I have made changes in code :

Present code:





*f = open("output.txt")content=f.read().split('\n') f.close()for lines in
content:*
*  *
*content.clear()*

Previous code:






*f = open("output.txt") content=io.StringIO(f.read()) f.close()for lines in
content:  *
*content.close()*


   Now I have found that memory use is roughly 1.5 times the size of text
file. Previously it was around 4-5 times. Its remarkable change. Waiting
for more suggestions.

Thanks,



On Mon, Nov 4, 2013 at 5:05 PM, Alan Gauld wrote:

> On 04/11/13 11:07, Amal Thomas wrote:
>
> I am currently using this method to load my text file:
>> *f = open("output.txt")
>> content=io.StringIO(f.read())
>> f.close()*
>>
>>   But I have found that this method uses 4 times the size of text file.
>>
>
> So why not use
>
>
> f = open("output.txt")
> content=f.read()
> f.close()
>
> And process the file as a raw string?
>
> Is there a reason for using the StringIO?
>
> --
> Alan G
> Author of the Learn to Program web site
> http://www.alan-g.me.uk/
> http://www.flickr.com/photos/alangauldphotos
>
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor
>



-- 



*AMAL THOMASFourth Year Undergraduate Student Department of Biotechnology
IIT KHARAGPUR-721302*
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Load Entire File into memory

2013-11-04 Thread Amal Thomas
Yes I have found that after loading to RAM and then reading lines by lines
saves a huge amount of time since my text files are very huge.


On Mon, Nov 4, 2013 at 6:46 PM, Alan Gauld wrote:

> On 04/11/13 13:06, Amal Thomas wrote:
>
>  Present code:
>>
>>
>> *f = open("output.txt")
>> content=f.read().split('\n')
>> f.close()
>>
>
> If your objective is to save time, then you should replace this with
> f.readlines() which will save you reprocesasing the entire file to remove
> the newlines.
>
>  for lines in content:
>> *  *
>> *content.clear()*
>>
>
> But if you are processing line by line what makes you think that reading
> the entire file into RAM and then reprocessing it is faster than reading it
> line by line?
>
> Have you tried that on aqnother file and measutred any significant
> improvement? There are times when reading into RAM is faster but I'm not
> sure this will be one of them.
>
> for line in f:
>process line
>
> may be your best bet.
>
>  *f = open("output.txt")
>> content=io.StringIO(f.read())
>> f.close()
>> for lines in content:
>>
>> *
>> *content.close()*
>>
>
> --
> Alan G
> Author of the Learn to Program web site
> http://www.alan-g.me.uk/
> http://www.flickr.com/photos/alangauldphotos
>
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor
>



-- 



*AMAL THOMASFourth Year Undergraduate Student Department of Biotechnology
IIT KHARAGPUR-721302*
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Load Entire File into memory

2013-11-04 Thread Amal Thomas
Hi,
@Peter:
I have checked the execution time manually as well as I found it through my
code. During execution of my code, at start, I stored my initial time(start
time) to a variable  and at the end calculated time taken to run the code =
end time - start time. There was a significance difference in time.

Thanks,

On Mon, Nov 4, 2013 at 7:11 PM, Peter Otten <__pete...@web.de> wrote:

> Amal Thomas wrote:
>
> > Yes I have found that after loading to RAM and then reading lines by
> lines
> > saves a huge amount of time since my text files are very huge.
>
> How exactly did you find out? You should only see a speed-up if you iterate
> over the data at least twice.
>
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor
>



-- 



*AMAL THOMASFourth Year Undergraduate Student Department of Biotechnology
IIT KHARAGPUR-721302*
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Load Entire File into memory

2013-11-04 Thread Amal Thomas
@William:
Thanks,

My Line size varies from 40 to 550 characters. Please note that text file
which I have to process is in gigabytes ( approx 50 GB ) . This was the
code which i used to process line by line without loading into memory.

*for lines in open('uniqname.txt'): *

* *

On Mon, Nov 4, 2013 at 7:16 PM, William Ray Wing  wrote:

> On Nov 4, 2013, at 8:30 AM, Amal Thomas  wrote:
> How long are the lines in your file?  In particular, are they many
> hundreds or thousands of characters long, or are they only few hundred
> characters, say 200 or less?
>
> Unless they are so long as to exceed the normal buffer size of your OS's
> read-ahead buffer, I strongly suspect that the big time sink in your
> attempt to read line-by-line was some inadvertent inefficiency that you
> introduced.  Normally, when reading from a text file, python buffers the
> reads (or uses the host OS buffering).  Those reads pull in huge chunks of
> text WAY ahead of where the actual python processing is going on, and are
> VERY efficient.
>
> -Bill




-- 

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


Re: [Tutor] Load Entire File into memory

2013-11-04 Thread Amal Thomas
@Dave: thanks.. By the way I am running my codes on a server with about
100GB ram but I cant afford my code to use 4-5 times the size of the text
file. Now I am using  read() / readlines() , these seems to be more
efficient in memory usage than io.StringIO(f.read()).


On Mon, Nov 4, 2013 at 9:23 PM, Steven D'Aprano  wrote:

> On Mon, Nov 04, 2013 at 02:48:11PM +, Dave Angel wrote:
>
> > Now I understand.  Processing line by line is slower because it actually
> > reads the whole file.  The code you showed earlier:
> >
> > >I am currently using this method to load my text file:
> > > *f = open("output.txt")
> > > content=io.StringIO(f.read())
> > > f.close()*
> > >   But I have found that this method uses 4 times the size of text file.
> >
> > will only read a tiny portion of the file.  You don't have any loop on
> > the read() statement, you just read the first buffer full. So naturally
> > it'll be much faster.
>
>
> Dave, do you have a reference for that? As far as I can tell, read()
> will read to EOF unless you open the file in non-blocking mode.
>
> http://docs.python.org/3/library/io.html#io.BufferedIOBase.read
>
>
> > I am of course assuming you don't have a machine with 100+ gig of RAM.
>
> There is that, of course. High-end servers can have multiple hundreds of
> GB of RAM, but desktop and laptop machines rarely have anywhere near
> that.
>
>
> --
> Steven
>
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor
>



-- 



*AMAL THOMASFourth Year Undergraduate Student Department of Biotechnology
IIT KHARAGPUR-721302*
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Load Entire File into memory

2013-11-04 Thread Amal Thomas
@Joel: The code runs for weeks..input file which I have to process in very
huge(in 50 gbs). So its not a matter of hours.its matter of days and
weeks..I was using C++. Recently I switched over to Python. I am trying to
optimize my code to get the outputs in less time and memory efficiently.


On Mon, Nov 4, 2013 at 9:57 PM, Joel Goldstick wrote:

>
>
>
> If you are new to python why are you so concerned about the speed of
> your code.  You never say how long it takes.  Do these files take
> hours to process? or minutes or seconds?I suggest you write your
> code in a way that is clear and understandable, then try to optimize
> it if necessary.
>
>

-- 


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


Re: [Tutor] Load Entire File into memory

2013-11-04 Thread Amal Thomas
@Steven: Thanks... Right now I cant access the files. I will send you the
output when I can.

--
Please try this little bit of code, replacing the file name with the
actual name of your 50GB data file:

import os
filename = "YOUR FILE NAME HERE"
print("File size:", os.stat(filename).st_size)
f = open(filename)
content = f.read()
print("Length of content actually read:", len(content))
print("Current file position:", f.tell())
f.close()


and send us the output.

-- 

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


Re: [Tutor] Load Entire File into memory

2013-11-04 Thread Amal Thomas
@Steven: Thank you...My input data is basically AUGC and newlines... I
would like to know about bytearray technique. Please suggest me some links
or reference.. I will go through the profiler and check whether the code
maintains linearity with the input files.




> > It's probably worth putting some more timing statements into your code
> > to see where the time is going because it's not the reading from the
> > disk that's the problem.
>
> The first thing I would do is run the code on three smaller sample
> files:
>
> 50MB
> 100MB
> 200MB
>
> The time taken should approximately double as you double the size of the
> file: say it takes 2 hours to process the 50MB file, 4 hours for the
> 100MB file and 8 hours for the 200 MB file, that's linear performance
> and isn't too bad.
>
> But if performance isn't linear, say 2 hours, 4 hours, 16 hours, then
> you're in trouble and you *desperately* need to reconsider the algorithm
> being used. Either that, or just accept that this is an inherently slow
> calculation and it will take a week or two.
>
> Amal, another thing you should try is use the Python profiler on your
> code (again, on a smaller sample file). The profiler will show you where
> the time is being spent.
>
> Unfortunately the profiler may slow your code down, so it is important
> to use it on manageable sized data. The profiler is explained here:
>
> http://docs.python.org/3/library/profile.html
>
> If you need any help, don't hesitate to ask.
>
>
> > >trying to optimize my code to get the outputs in less time and memory
> > >efficiently.
> >
> > Memory efficiency is easy, do it line by line off the disk.
>
> This assumes that you can process one line at a time, sequentially. I
> expect that is not the case.
>
>
> --
> Steven
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor
>



-- 


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


Re: [Tutor] Load Entire File into memory

2013-11-05 Thread Amal Thomas
On Mon, Nov 4, 2013 at 10:00 PM, Steven D'Aprano 
wrote:
>

>
> import os
> filename = "YOUR FILE NAME HERE"
> print("File size:", os.stat(filename).st_size)
> f = open(filename)
> content = f.read()
> print("Length of content actually read:", len(content))
> print("Current file position:", f.tell())
> f.close()
>
>
> and send us the output.


 This is the output:
   File size: 50297501884
   Length of content actually read: 50297501884
   Current file position: 50297501884
This Code used 61.4 GB RAM and 59.6 GB swap (I had ensured that no other
important process were running in my server before running this :D)
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


[Tutor] Need to create code

2013-12-10 Thread Matthew Thomas

Write a function named SSN2Name with an interactive loop. The function takes 
the dictionary named data as
 input argument where this dictionary stores the key, value pairs of 
SSN, name of person. The SSN is in the string format 'xxx-xx-' and
 name is also a string. Each iteration of the functions's loop should 
prompt the user to enter an SSN in the required format and next, it 
should print the name of the person if he/she is found in the 
dictionary, otherwise a message like "person not found" if that SSN does
 not exist in the keys of the dictionary. The loop should stop iterating
 when the user inputs the empty string "" when prompted for SSN.
  Write the full function definition in your answer. The function outline is 
given below with comments provided as code hints -
  def SSN2Name(data):  
   # create a loop that repeats forever (while True loop) 
# within the loop prompt user for SSN
# if user input is empty string break out of loop
# if user input is an SSN found as a key in the dictionary, print 
the value corresponding to that key
# if user input is not found as a key in the dictionary print 
message saying person was not found

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


[Tutor] Web scrapping

2013-12-12 Thread Amal Thomas
Hi,

  I am new to python3. I am working in computational biology. I need to
submit many sequence (one by one) to a http web server (
http://mfold.rna.albany.edu/?q=mfold/RNA-Folding-Form) . After the
processing I need to download the output file. There is an offline package
for this server but certain features not available in it. The url for each
request is not unique. Is there anyway to do this process by a code ie
sending the request, downloading etc. Any suggestions or useful material
will be of great help.
Working on
Python 3.3.1,ubuntu 13.04(Linux  3.8.0-29-generic x64)

Thanking you,

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


Re: [Tutor] Web scrapping

2013-12-12 Thread Amal Thomas
Hi,

  Ya its kind of user filling out a form and sending request.
 Steps are like this.
 1. I need to submit my sequence in webserver ( like filling out a form in
web)
 2. Then I have to give a request for format sequence(available in the
link: http://mfold.rna.albany.edu/?q=mfold/RNA-Folding-Form )
 3. Then further steps downloading the output..

Thanks,



On Fri, Dec 13, 2013 at 12:19 AM, Joel Goldstick
wrote:

>
>
>
> On Thu, Dec 12, 2013 at 1:41 PM, Amal Thomas wrote:
>
>> Hi,
>>
>>   I am new to python3. I am working in computational biology. I need to
>> submit many sequence (one by one) to a http web server (
>> http://mfold.rna.albany.edu/?q=mfold/RNA-Folding-Form) . After the
>> processing I need to download the output file. There is an offline package
>> for this server but certain features not available in it. The url for each
>> request is not unique. Is there anyway to do this process by a code ie
>> sending the request, downloading etc. Any suggestions or useful material
>> will be of great help.
>> Working on
>> Python 3.3.1,ubuntu 13.04(Linux  3.8.0-29-generic x64)
>>
>> Thanking you,
>>
>> Amal
>>
>> ___
>> Tutor maillist  -  Tutor@python.org
>> To unsubscribe or change subscription options:
>> https://mail.python.org/mailman/listinfo/tutor
>>
>>
> Python comes with the urllib module, but there is a third party module
> called Requests (http://requests.readthedocs.org/en/latest/).  This will
> let you fill in the form via your program, and also download some document.
>
> Your subject 'screen scraping' is puzzling.  It seems what you are asking
> is how to make your program act like a user filling out a form.  Or i
> completely misunderstood.
>
> --
> Joel Goldstick
> http://joelgoldstick.com
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Web scrapping

2013-12-12 Thread Amal Thomas
On Fri, Dec 13, 2013 at 12:29 AM, Joel Goldstick
wrote:

>
>
> So, read the Requests tutorial, and study the POST examples as POST is the
> http method that is used when filling in a form.  First you will need to
> examine the form to learn the names of the fields you need to provide data
> for.
>

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


[Tutor] I am teaching my students Python the second semester using www.LearnStreet.com ( http://www.learnstreet.com/ ). I am in need of some help. I am having a problem with the Lists-Set 1 exercise 1

2014-02-04 Thread Thomas Maher
I am teaching my students Python the second semester using www.LearnStreet.com 
( http://www.learnstreet.com/ ).  I am in need of some help.  I am having a 
problem with the Lists-Set 1 exercise 18.  The problem is below.  I have put in 
several codes and the output is 5, which is the right answer.  But it is asking 
for List's index logic.  I have tried support with LearnStreet but they have 
yet to respond.  Thank you for your time.
 
 
Tommy Maher
18 : Finding the length of nested lists.

Create two lists list1 = [1,2,3,4,5] and list2 = [6,7,8,list1]. Write a code to 
find the length of list1 in list2 using for loop. 

Use the if statement to check elements in the list2.

 
def len_of_innerlist(list2):
# your code here

list1 = [1,2,3,4,5]
print len_of_innerlist([6,7,8,list1])
 
 
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


[Tutor] Variable data to CSV

2015-02-27 Thread Thomas Toker
Hey all so I'm new to python(like 2 days ago new) I need to find the device 
address, usb port, and number of times the error occurs Heres what I have: 
import re import csv
import reimport csvf = open("file.txt", "r") #location of log file
searchlines = f.readlines()                   #create list from 
filef.close()for element in searchlines:     usbPres = 
re.search('(USB)',element)  #pattern to find usb lines     devAddr = 
re.search('(address)\s\d+',element)  #parsing pattern for device address     
port = re.search('(port)\s\d',element)  #parsing pattern for port     if 
usbPres:         This is where I get lost because I want to assign the correct 
port to device address and then count number of time it failed before a new 
device is inserted into that port. then write it to a CSV

 SAMPLE TEXT ***
[11883.112089] hub 1-0:1.0: Cannot enable port 3. Maybe the USB cable is bad?
[11883.224080] usb 1-7: new high speed USB device using ehci_hcd and address 42
[11883.328151] hub 1-0:1.0: unable to enumerate USB device on port 7
[11904.472097] hub 1-0:1.0: Cannot enable port 3. Maybe the USB cable is bad?
[11907.440096] hub 1-0:1.0: Cannot enable port 3. Maybe the USB cable is bad?
[11910.408093] hub 1-0:1.0: Cannot enable port 3. Maybe the USB cable is bad?
[11913.376095] hub 1-0:1.0: Cannot enable port 3. Maybe the USB cable is bad?
[11913.616090] usb 1-7: new high speed USB device using ehci_hcd and address 47
[11913.716121] hub 1-0:1.0: unable to enumerate USB device on port 7
[11927.340096] hub 1-0:1.0: Cannot enable port 3. Maybe the USB cable is bad?
[11930.308096] hub 1-0:1.0: Cannot enable port 3. Maybe the USB cable is bad?
[11933.276124] hub 1-0:1.0: Cannot enable port 3. Maybe the USB cable is bad?
[11936.244118] hub 1-0:1.0: Cannot enable port 3. Maybe the USB cable is bad?
[11939.212116] hub 1-0:1.0: Cannot enable port 7. Maybe the USB cable is 
bad?Any help is much appreciated.Tom


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


[Tutor] classproperty for Python 2.7 (read-only enough)

2017-04-18 Thread Thomas Güttler

I would like to have read-only class properties in Python.

I found this 
http://stackoverflow.com/questions/128573/using-property-on-classmethods
But there are a lot of discussions of things which I don't understand.

I want to be a user of class properties, not an implementer of the details.

I found this: https://pypi.python.org/pypi/classproperty

But above release is more then ten years old. I am unsure if it's dead or 
mature.

I am using Python 2.7 and attribute getters would be enough, no attribute 
setter is needed.

My use case is configuration, not fancy algorithms or loops.

Regards,
  Thomas Güttler

--
Thomas Guettler http://www.thomas-guettler.de/
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] classproperty for Python 2.7 (read-only enough)

2017-04-19 Thread Thomas Güttler

Am 18.04.2017 um 13:17 schrieb Peter Otten:

Thomas Güttler wrote:


I would like to have read-only class properties in Python.

I found this
http://stackoverflow.com/questions/128573/using-property-on-classmethods
But there are a lot of discussions of things which I don't understand.

I want to be a user of class properties, not an implementer of the
details.

I found this: https://pypi.python.org/pypi/classproperty

But above release is more then ten years old. I am unsure if it's dead or
mature.

I am using Python 2.7 and attribute getters would be enough, no attribute
setter is needed.

My use case is configuration, not fancy algorithms or loops.


Like this?

$ cat classproperty.py
class classproperty(object):
def __init__(self, fget):
self.fget = fget
def __get__(self, inst, cls):
return self.fget(cls)


class Foo(object):
FOO = 42
@classproperty
def foo(cls):
return cls.FOO

print "Foo.foo =", Foo.foo
print "Foo().foo =", Foo().foo
$ python2 classproperty.py
Foo.foo = 42
Foo().foo = 42


Nice, if it is that simple.

Is there a reason why this is not in the standard library?

Regards,
  Thomas Güttler



--
Thomas Guettler http://www.thomas-guettler.de/
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


[Tutor] classproperty, three times in virtualenv

2017-04-20 Thread Thomas Güttler



Am 19.04.2017 um 09:43 schrieb Alan Gauld via Tutor:

On 19/04/17 08:28, Thomas Güttler wrote:


Nice, if it is that simple.

Is there a reason why this is not in the standard library?


Probably because it is such a rare use case and because
its not that hard to do yourself if you really need it.

But the standard library, like any open source project,
develops as people need things. If nobody needs something
it will never be built and therefore never be added to
the library. I'd guess this falls into that category.


In my virtualenv it looks like it has three implementations. Maybe more with a 
different name.

user@host> find src/ lib/ -name '*.py'|xargs grep -Ei '(def|class) 
classproperty'

lib/python2.7/site-packages/logilab/common/decorators.py:class 
classproperty(object):
lib/python2.7/site-packages/django/utils/decorators.py:class 
classproperty(object):
lib/python2.7/site-packages/mptt/models.py:class classpropertytype(property):



Regards,
  Thomas


--
Thomas Guettler http://www.thomas-guettler.de/
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


[Tutor] classproperty: readonly and inheritance - not more needed

2017-04-20 Thread Thomas Güttler



Am 19.04.2017 um 11:16 schrieb Steven D'Aprano:

On Wed, Apr 19, 2017 at 09:28:26AM +0200, Thomas Güttler wrote:

[code for a classproperty]


Nice, if it is that simple.

Is there a reason why this is not in the standard library?


I haven't had a chance to test Peter's classproperty code yet, but I
don't expect it to be that simple. People have asked for it before, and
even Guido himself (the inventor of Python) has agreed that if it
existed he'd use it, but the proposals have (so far) always stumbled on
two factors:

- there are not a lot of uses for classproperty that ordinary property
  isn't "good enough" for;

- its hard to get classproperty to work right.


What is "righ"?

In my case a read-only classproperty is enough. Inheritance should be supported.

I don't have a usecase for a setter.

Regards,
  Thomas Güttler
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] classproperty: readonly and inheritance - not more needed

2017-04-23 Thread Thomas Güttler



Am 20.04.2017 um 14:26 schrieb Steven D'Aprano:

On Thu, Apr 20, 2017 at 10:39:57AM +0200, Thomas Güttler wrote:


- its hard to get classproperty to work right.


What is "righ"?

In my case a read-only classproperty is enough. Inheritance should be
supported.

I don't have a usecase for a setter.


The standard library is not just for you :-)

If Peter's solution is "good enough" for you, then great, go ahead and
use it. But beware: of the two implementations I know, you cannot have
both:

- access from instances;
- read-only property;

You can have access from instances, but then the classproperty is not
read-only. Or you can have read-only access, but only from the class
object.


I can't follow what you. What do you mean with "... is not read-only".

This snippet works fine:

{{{

class classproperty(object):
def __init__(self, f):
self.f = f
def __get__(self, obj, owner):
return self.f(owner)

class Foo(object):
@classproperty
def my_prop(cls):
return 42

print Foo.my_prop

print Foo().my_prop
}}}

Regards,
  Thomas

--
Thomas Guettler http://www.thomas-guettler.de/
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] classproperty: readonly and inheritance - not more needed

2017-04-24 Thread Thomas Güttler


Now the "not read-only" part:


Foo.my_prop = "whatever"
Foo.my_prop

'whatever'

You now have a string attribute, the property is lost. Methods behave the
same way and it's generally not a problem, but you should at least be aware
of this behaviour.


Yes, now I understand you. Thank you

Regards,
  Thomas Güttler


--
Thomas Guettler http://www.thomas-guettler.de/
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


[Tutor] if __name__=='main' vs entry points: What to teach new comers?

2017-08-01 Thread Thomas Güttler

I have a friend who is a talented shell script writer. He is a linux guru since
several years.

He asked me if "if __name__=='main':" is state of the art if you want
to translate a shell script to python.

I started to stutter and did not know how to reply.

I use Python since several years and I use console_script in entry_points of 
setup.py.

I am very unsure if this is the right way if you want to teach a new comers the 
joy of python.

In the current context we want to translate a bunch of shell scripts to python 
scripts.

What do you think?

Regards,
  Thomas Güttler


--
Thomas Guettler http://www.thomas-guettler.de/
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


[Tutor] __main__.py file Was: if __name__=='main' vs entry points: What to teach new comers?

2017-08-02 Thread Thomas Güttler



Do both. If you’re making a package, create a __main__.py file as well
so your package is usable with `python -m somepackage`. On the other
hand, if you’re making things more akin to shell scripts, using just
entry_points makes stuff harder, because you need to install the code
(and write a setup.py), as opposed to just putting the script
somewhere in $PATH.



Up to now I never did this. Maybe I will do this in the future.

thank you,
  Thomas Güttler

--
Thomas Guettler http://www.thomas-guettler.de/
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] if __name__=='main' vs entry points: What to teach new comers?

2017-08-02 Thread Thomas Güttler



Am 02.08.2017 um 05:35 schrieb Abdur-Rahmaan Janhangeer:

what difference do you make between python scripts and python code files?

are codes relating to file manipulation called scripts?


Do you ask this question all people on this list, or only one particular person?

I don't know the difference between python scripts and python code files.

Regards,
  thomas

--
Thomas Guettler http://www.thomas-guettler.de/
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] if __name__=='main' vs entry points: What to teach new comers?

2017-08-02 Thread Thomas Güttler



Am 02.08.2017 um 05:51 schrieb Steven D'Aprano:

On Wed, Aug 02, 2017 at 11:22:00AM +1000, Ben Finney wrote:

Steven D'Aprano  writes:


On Tue, Aug 01, 2017 at 04:54:40PM +0200, Thomas Güttler wrote:

[...]

I use Python since several years and I use console_script in
entry_points of setup.py.


What's console_script in entry_points of setup.py?


It is an advanced feature in Setuptools, that allows defining a function
in the code base as the entry point for external use.

The “console_scripts” entry points tell Setuptools to, at installation
time, create a wrapper script that invokes that function as a
command-line program.

 
https://setuptools.readthedocs.io/en/latest/setuptools.html#automatic-script-creation>


Thanks.

Now that I have learned that, I shall do my best to forget it :-)


Maybe I am doing something wrong.  I was proud because I did use 
“console_scripts” entry points.
I thought this is the right way of doing it. Doing things the right way always 
makes my feel so very good :-)

Regards,
  Thomas


--
Thomas Guettler http://www.thomas-guettler.de/
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


[Tutor] setup.py "script" vs "console_scripts" Was: if __name__=='main' vs entry points: What to teach new comers?

2017-08-03 Thread Thomas Güttler



Am 02.08.2017 um 18:06 schrieb Wolfgang Maier:

On 08/02/2017 04:57 PM, Steven D'Aprano wrote:

On Wed, Aug 02, 2017 at 10:48:39PM +1000, Ben Finney wrote:

Thomas Güttler  writes:


Maybe I am doing something wrong.  I was proud because I did use
“console_scripts” entry points.


Did someone lead you to believe it was wrong? Setuptools console_scripts
entry points are a good tool.

My point was that it is an *advanced* tool, difficult to use and also
difficult to explain because the concepts are advanced.


Can you explain the use-case for when somebody might want to use
console_scripts entry points?

I have a module with a main() function and an "if __name__ == ..."
guard. Under what circumstances is that not sufficient, and I would want
console_scripts?



If you install things using pip/setuptools and have defined a
console_scripts entry point for it, then the corresponding wrapper
script will be installed in whatever is considered the scripts directory
at install time on that machine. With a bit of luck the entry point will
thus be executable directly without any end-user intervention (like
adding folders to $PATH and chmodding files).
Personally, I always found it straightforward to write the wrapper
script myself, then define this as a 'scripts' file in the package
layout of my setup.py, but people's MMV.



I was not aware of "scripts" in setup.py. But I found docs:

  http://python-packaging.readthedocs.io/en/latest/command-line-scripts.html

Why are there two ways: "script" vs "console_scripts entry-point"?

Regards,
  Thomas


--
Thomas Guettler http://www.thomas-guettler.de/
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] setup.py "script" vs "console_scripts" Was: if __name__=='main' vs entry points: What to teach new comers?

2017-08-04 Thread Thomas Güttler



Am 04.08.2017 um 02:50 schrieb Ben Finney:

Thomas Güttler  writes:


Why are there two ways: "script" vs "console_scripts entry-point"?


Because Distutils implements only ‘scripts’, and that's not capable
enough for what people need so Setuptools implements entry points.

In other words: One of them is in the standard library and does
something; the other is third-party and can do more.

That answers why there are two. But maybe you wanted to ask some
underlying question?


The underlaying question is: Imangine you are a newcomer. And there
are two more choices. You need a guide like 'if unsure do x'. With
other words: What is the sane default choice?

Chris wrote "Simple: `scripts` are legacy."

You say it is the standard, and console_scripts is from a third party.

For me "legacy" sound like "don't go this old way".

For me "third party" sounds like "don't go this way, stick to the standard".

I feel stupid since I have no clue.

Regards,
  Thomas Güttler

--
Thomas Guettler http://www.thomas-guettler.de/
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] setup.py "script" vs "console_scripts" Was: if __name__=='main' vs entry points: What to teach new comers?

2017-08-07 Thread Thomas Güttler



Am 05.08.2017 um 06:14 schrieb Ben Finney:

Thomas Güttler  writes:


The underlaying question is: Imangine you are a newcomer.


A newcomer is in a tough position when it comes to packaging and
distributing Python code, especially the command-line programs.

There has been significant progress on this in recent years. The
Setuptools third-party library is a lot saner, the inclusion of ‘pip’ in
standard installs makes it much broader in scope.

But *not* in the standard library today, it's true.


You need a guide like 'if unsure do x'. With other words: What is the
sane default choice?


There isn't a good answer to that question, today.

The best answer today is: Read the guides from the Python Packaging
Authority, and stay abreast of developments because this continues to
change.

Maybe eventually the ongoing work of the PyPA will be settled enough
that it can update the standard library Distutils. But not today.



You say that there isn't a good answer to that question, today.

For me the question was: setup.py "script" vs "console_scripts" ?

I found this: 
https://packaging.python.org/tutorials/distributing-packages/#console-scripts

You say that there isn't a good answer to that question, today.

I can't follow.

Why is "the sane default is 'use console_scripts entry-point in setup.py'" not 
a good answer?

Regards,
  Thomas Güttler



--
Thomas Guettler http://www.thomas-guettler.de/
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


[Tutor] The sane default choice is entry_points console_scripts Was: if __name__=='main' vs entry points: What to teach new comers?

2017-08-09 Thread Thomas Güttler



Am 08.08.2017 um 12:56 schrieb Chris Warrick:

On 8 August 2017 at 03:30, Ben Finney  wrote:

Thomas Güttler  writes:


Why is "the sane default is 'use console_scripts entry-point in
setup.py'" not a good answer?


Because third-party Setuptools is required for entry points, which means
entry points cannot be a default choice.

It may well be a good choice for many cases. But that's a different
matter from it being a good *default* choice; it can only be a default
choice if it's in the standard library.


While setuptools is not officially part of the stdlib, it *is*
recommended by the official documentation, the dev team, and it’s
available pretty much everywhere. setuptools can’t be in stdlib,
because it’s moving too fast for stdlib to keep up.

Look here: http://pythonwheels.com/ — 254 of the top 360 packages on
PyPI use wheels. It means that at least that many use setuptools;
sometimes with a distutils fallback, but often without one. Moreover,
many of the packages without wheels use setuptools as well.






The sane default choice is entry_points.


Sounds good. Thank you for this statement.

Regards,
  Thomas Güttler




--
Thomas Guettler http://www.thomas-guettler.de/
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


[Tutor] Percentage of installations without setuptools (Was if __name__=='__main__' ...)

2017-08-11 Thread Thomas Güttler

I start a new thread, since this is a new topic.

I don't have the deep knowledge like Chris, Steven or Alan.

I guess most python installations have setuptools. But this is only my naive 
vague guess.

How high is the percentage of python installation which don't have setuptools?

I have no clue. Is it 5%, 10%, 15% ...?

I know there is no definite answer to this question. But you can guess this 
better than me.

Regards,
 Thomas Güttler



Am 10.08.2017 um 12:01 schrieb Chris Warrick:
> On 9 August 2017 at 23:15, Steven D'Aprano  wrote:
>> On Tue, Aug 08, 2017 at 12:56:56PM +0200, Chris Warrick wrote:
>>
>>> While setuptools is not officially part of the stdlib,
>>
>> This is the critical factor. How can you use *by default* something that
>> is *NOT* supplied by default?
>>
>> Obviously you cannot. It is physically impossible.
>
>
> The problem with setuptools (and pip) is that they are not first-party
> stdlib members, but they are not third-party packages either. They’re
> somewhere in between. They have been blessed by the core developers.
> And yes, setuptools might be in all the places you mentioned:
>
>> But this does NOT hold for everyone, possibly not even for the majority
>> of Python users. For example:
>>
>> - students using their school's computers;
>>
>> - corporate and government users using a SOE (Standard Operating
>>Environment);
>>
>> - people using a system where, for policy reasons, only the
>>standard library is permitted.
>
> * If those computers run Windows (as they often do) and run a recent
> Python version (3.4 or newer/2.7.9 or newer), setuptools will be
> installed, unless the IT people explicitly disabled ensurepip.
> * On macOS, setuptools will be installed if they’re using the system
> Python, the python.org installers (which are not uninstallable), or
> Python from Homebrew. The last two also have pip, and system Python
> has ensurepip.
> * On Linux, setuptools/pip is likely to be there, but it’s not
> required in all distributions. (Fedora mandates setuptools; Debian
> even rips out ensurepip by default and hides it in python3-venv
> because reasons…)
>
> If the users are meant to install Python packages, their system
> administrators would take care of that — either by setting up
> setuptools/pip and perhaps virtualenv, or taking install requests from
> users. If users are not supposed to be running setuptools/pip, they
> probably shouldn’t, but they can still install it from ensurepip or
> downloading get-pip.py.
>
>> I've worked in places where installing unauthorized software was a
>> firing offence.
>
> Those people don’t need setuptools. Those people should not be using
> distutils either. They might not even be allowed to download packages
> and run __main__.py without installation.
>
--
Thomas Guettler http://www.thomas-guettler.de/


--
Thomas Guettler http://www.thomas-guettler.de/
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Percentage of installations without setuptools (Was if __name__=='__main__' ...)

2017-08-14 Thread Thomas Güttler



Am 13.08.2017 um 02:12 schrieb Steven D'Aprano:

On Fri, Aug 11, 2017 at 02:35:00PM +0200, Thomas Güttler wrote:


How high is the percentage of python installation which don't have
setuptools?

I have no clue. Is it 5%, 10%, 15% ...?

I know there is no definite answer to this question. But you can guess this
better than me.


Somewhere between 0.1% and 99.9%.

For what little it is worth, out of the 9 versions of Python I have
installed on my personal machines, setuptools is installed for 4 of
them. On work machines, 2 out of 5 have setuptools installed. So in
total, 6 out of 14 Python installations I have access to include
setuptools. So 57% *don't* have setup tools.

Really Thomas, why do you care?


Good question. Why do I care ...

If there is no solid ground, no sane defaults, then young and talented 
programmers
waste time. I just don't know why, but this makes me feel pain.


If you want to require setuptools for
your packages, go right ahead. If you want to tell people that using
setuptools is the best choice, or the most popular choice, or the
smartest choice, do so.

Just don't say it is the "default choice" because that is silly. The
whole purpose of something being *default* is so that you DON'T have to
make a choice. Obviously that doesn't apply to choosing a packaging
library, and especially not to choosing a packaging language which may
not even be present. Even if its only missing 1% of the time.



As a third-party author, the sorts of people who don't have setuptools
installed either won't be installing your software at all, or will be
installing it from source.




--
Thomas Guettler http://www.thomas-guettler.de/
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


  1   2   >