[Tutor] Why VPython can't be searched out in PyPI?

2012-10-17 Thread Dae James
I found that VPython is not in PyPI(python packet index from www.python.org). 
Why ?




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


Re: [Tutor] Why VPython can't be searched out in PyPI?

2012-10-17 Thread Mark Lawrence

On 17/10/2012 09:23, Dae James wrote:

I found that VPython is not in PyPI(python packet index from www.python.org). 
Why ?

Dae James



The author(s) have chosen not to place it there.

--
Cheers.

Mark Lawrence.

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


Re: [Tutor] managing memory large dictionaries in python

2012-10-17 Thread Mark Lawrence

On 17/10/2012 03:22, Alexander wrote:

On Tue, Oct 16, 2012 at 20:43 EST, Mark Lawrence
 wrote:

For the record Access is not a database, or so some geezer called Alex
Martelli reckons http://code.activestate.com/lists/python-list/48130/, so
please don't shoot the messenger:)
Cheers.
Mark Lawrence.


Mark I don't believe your response is relevant or helpful to the
original post so please don't hijack.




On an open forum I'll say what I like thank you.

--
Cheers.

Mark Lawrence.

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


Re: [Tutor] CSV -> sqlite tables with foreign keys

2012-10-17 Thread eryksun
On Tue, Oct 16, 2012 at 11:59 PM, Monte Milanuk  wrote:
>
> address = list(row)
> address.append(person)
> row = tuple(address)

The rows from the csv.reader are already lists. Also, the parameter
list in the 2nd argument only needs to be a sequence (e.g. tuple,
list, string), or it can also be a dict if the statement uses named
placeholders.

> from what I've found on the web, I get the distinct impression
> that converting from a tuple to a list and back is considered
> poor practice at best and generally to be avoided.

To update a record in a tuple you can use slicing and concatenation
(+) as an alternative to creating a temporary list.  A list is more
applicable to homogenous data (e.g. a list of tuples, each a data
record). If you want a container for a record that you can modify more
efficiently, use a dict or a custom object. For the latter, look into
ORMs such as Storm:

https://storm.canonical.com/

> Any suggestions?

I found a Stack Overflow answer that uses a table "view" combined with
an "instead of" trigger to update two tables with one insert.

http://stackoverflow.com/a/11715983/205580

Here's my meager attempt at an adaptation (some names have been
changed to protect the innocent...):

import csv
import sqlite3

con = sqlite3.connect(':memory:')
cur = con.cursor()

cur.execute('''create table person (
  id integer primary key autoincrement,
  firstname, midinit, lastname, birthdate)
''')

cur.execute('''create table address (
  id integer primary key autoincrement,
  person_id integer references person not null,
  street, city, state, zipcode)
''')

cur.execute('''create view person_view as
  select
person.firstname, person.midinit, person.lastname,
person.birthdate, address.street, address.city,
address.state, address.zipcode
  from
person inner join address on person.id = address.person_id
''')

cur.execute('''create trigger person_view_insert
  instead of insert on person_view
  begin
insert into
  person (firstname, midinit, lastname, birthdate)
  values (new.firstname, new.midinit, new.lastname,
  new.birthdate);
insert into
  address (person_id, street, city, state, zipcode)
  values ((select last_insert_rowid()),
  new.street, new.city, new.state, new.zipcode);
  end
''')

import io
data = io.BytesIO(b'''\
John,G.,Smith,1972-11-10,123 Any Place,Somewhere,Missouri,58932
Jane,L.,Jones,1971-12-20,321 Some Place,Anywhere,Kansas,12345
''')

reader = csv.reader(data)
for row in reader:
cur.execute('''insert into
  person_view (firstname, midinit, lastname, birthdate,
   street, city, state, zipcode)
  values (?,?,?,?,?,?,?,?)''', row)

# output
for row in cur.execute('select * from person'):
print row
for row in cur.execute('select * from address'):
print row


person table:

(1, u'John', u'G.', u'Smith', u'1972-11-10')
(2, u'Jane', u'L.', u'Jones', u'1971-12-20')

address table:

(1, 1, u'123 Any Place', u'Somewhere', u'Missouri', u'58932')
(2, 2, u'321 Some Place', u'Anywhere', u'Kansas', u'12345')
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Why difference between printing string & typing its object reference at the prompt?

2012-10-17 Thread Dwight Hutto
If your app has  a standard usage of phrases, you can place a file in
that translates a tag into a particular language phrase.



if submit_tag_selection == 'english':
 submit = 'Submit'
if submit_tag_selection == 'english':
 submit = 'Soumettre'

Of course this could be done without the if, you would just translate
the normal selections within a file with the commonly used phrases in
the app, and substitute it within a parse for:

x = open('translate_file_french', 'r')
for line in x:
 if line.split('=')[0] == 'Submit':
   print '%s'   %   (line.split('=')[1])

'Soumettre'

*Untested, but should work


-- 
Best Regards,
David Hutto
CEO: http://www.hitwebdevelopment.com
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] modulo

2012-10-17 Thread Dwight Hutto
__
>>> I'm not a professional programmer, so I might be way off base here.

You mean you haven't dealt with this subject yet...

But what I like about Pythons modulo solution is that I can use it to
right and left shift in lists or tuples, and I will link to the first
element when I right shift past the last element and link to the last
element when I left shift past the first element. In other words I can
consider the last as a chain where the last and the first element are
connected. This I find useful in surprisingly many situations.

It's uised for, what it's used for, until you know the full lower
level implementation/parsing of objects like immutables(tuples), and
mutables(lists,dicts,strings,etc

>>
>>
> Certainly, but you've never had to do that with lists or tuples having
> negative lengths.  It's a negative modulus that I'm complaining about.

Can you show some example code here?

-- 
Best Regards,
David Hutto
CEO: http://www.hitwebdevelopment.com
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] managing memory large dictionaries in python

2012-10-17 Thread Dwight Hutto
On Tue, Oct 16, 2012 at 12:57 PM, Abhishek Pratap
 wrote:
> Hi Guys
>
> For my problem I need to store 400-800 million 20 characters keys in a
> dictionary and do counting. This data structure takes about 60-100 Gb
> of RAM.
> I am wondering if there are slick ways to map the dictionary to a file
> on disk and not store it in memory but still access it as dictionary
> object. Speed is not the main concern in this problem and persistence
> is not needed as the counting will only be done once on the data. We
> want the script to run on smaller memory machines if possible.
>
> I did think about databases for this but intuitively it looks like a
> overkill coz for each key you have to first check whether it is
> already present and increase the count by 1  and if not then insert
> the key into dbase.
>
> Just want to take your opinion on this.
>
> Thanks!
> -Abhi
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor

My inexperienced advice would be to begin with the storage areas
available. I would begin by eliminating certain things such as:

x = {'one_entry' : 1}

into

x = {'one_entry':1}

To map, you would want maybe different db files that contain certain
info within a certain range. 0-1000 entries in the first file, etc.

os.walk a directory, and find the mapped file in a particular range
file, then go straight to the entry needed.

Make the dict one long line, and you could eliminate any /n newline chars.

 I could do better with more time, but that seems like a good solution
at this point.

Best Regards,
David Hutto
CEO: http://www.hitwebdevelopment.com
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Python Error

2012-10-17 Thread Benjamin Lee
Hello,
I am using python to calculate distances across the cell. 
I used this command:  python calculate_distances.py
This was the response:
Traceback (most recent call last):
file "calculate_distances.py" line 4, in 
import celltool.simple_interface as si
ImportError: No module named celltool.simple_ interface


I am not sure how to correct this error.
Thank you for your time,
Ben___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] program for a problem

2012-10-17 Thread Tharuni Dheeraj
please send me the program for the following que:

Write a program that asks the user for a dollar amount.It then reports the
corresponding number of euros by using the current exchange rate.
--
Regards,
Tharuni Dheeraj
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] modulo

2012-10-17 Thread Jan Karel Schreuder
 

On Oct 7, 2012, at 8:06 PM, Dave Angel  wrote:

> On 10/07/2012 08:00 PM, Jan Karel Schreuder wrote:
>> 
>> 
>> On Oct 7, 2012, at 7:24 PM, Dave Angel  wrote:
>> 
>> 
> 
>>> 
>>> It still makes no sense to me.  There are at least two equally silly
>>> ways to define the results of a negative modulus, and you've properly
>>> described one of them, presumably the one that Python implements.
>>> 
>>> But I've used and abused about 35 languages over the years, and each
>>> makes its own choice for this.  I'd rather just call it undefined, and
>>> eliminate it.  That's what we did when the hardware guys couldn't decide
>>> how the hardware was going to respond to a particular microcode bit
>>> pattern.  They documented it as undefined, and I made it illegal in the
>>> microcode assembler.
>>> 
>>> Fortunately, the OP isn't asking about this case, which is the other
>>> reason I didn't bother to describe what Python does.
>>> 
>>> 
>>> 
>>> -- 
>>> 
>>> DaveA
>>> ___
>>> I'm not a professional programmer, so I might be way off base here. But 
>>> what I like about Pythons modulo solution is that I can use it to right and 
>>> left shift in lists or tuples, and I will link to the first element when I 
>>> right shift past the last element and link to the last element when I left 
>>> shift past the first element. In other words I can consider the last as a 
>>> chain where the last and the first element are connected. This I find 
>>> useful in surprisingly many situations. 
>> 
>> 
> Certainly, but you've never had to do that with lists or tuples having
> negative lengths.  It's a negative modulus that I'm complaining about.
> 
> 
> -- 
> 
> DaveA

Aha. Yes I was talking about the solution to -3%5 and found the python solution 
(2) useful. I'm agnostic about x% -5
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Consecutive Sequence

2012-10-17 Thread syed zaidi

Hi,I am trying to develop a python code that takes a character string as input 
and  finds for the occurrence of letters that are occurring thrice or more 
consecutively.For E.g.
a = 'ataattaaacagagtgagcagt'In the output I want a list of those 
characters that are occuring thrice or more.
like in this case outout must b out_put = ['t','aaa','']
Can someone please suggest a code for this. 
  ___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Python incrementing problem

2012-10-17 Thread Stephen Hooker
Hello, I'm using Python 2.6 to generate switch lists for a model railroad.
I had some help before, possibly from this site but have encountered
another  problem. I realise the code could be better written, but learning
Python is a work in progress. The program works much as expected except
when I try to count & store the results of a random pick from a list of
rolling stock. If I try to store 1 result it works fine. If I try to store
more than 1 result I get one or the other, never both. The code is below
(not the whole program)

This works:

for i in range(1):

pos = random.randrange(0,len(rolling_stock_D))

pick = rolling_stock_D[pos]

for item in noDupes:

if item==pick:

break

else: # else for the loop, executed if the loop ran to exhaustion

noDupes.append(pick)


 for item in noDupes:

print item

print


 if item.find ("SDB") != -1:

SDB_count += 1

if item.find ("DDB") != -1:

DDB_count += 1



But this doesn't:

for i in range(2):

pos = random.randrange(0,len(rolling_stock_OS))

pick = rolling_stock_OS[pos]

for item in noDupes:

if item==pick:

break

else: # else for the loop, executed if the loop ran to exhaustion

noDupes.append(pick)


 for item in noDupes:

print item

print


 if item.find ("Flat") != -1:

Flat_count += 1

if item.find ("Gondola") != -1:

Gondola_count += 1


Any help would be much appreciated

thank you

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


Re: [Tutor] Tutor Digest, Vol 104, Issue 69

2012-10-17 Thread Cheng


tutor-requ...@python.org编写:

>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: CSV -> sqlite tables with foreign keys (eryksun)
>   2. Re: Why difference between printing string & typing its
>  object reference at the prompt? (Dwight Hutto)
>   3. Re: managing memory large dictionaries in python (Dwight Hutto)
>   4. Re: modulo (Dwight Hutto)
>   5. program for a problem (Tharuni Dheeraj)
>   6. Consecutive Sequence (syed zaidi)
>
>
>--
>
>Message: 1
>Date: Wed, 17 Oct 2012 05:19:27 -0400
>From: eryksun 
>To: Monte Milanuk 
>Cc: Tutor@python.org
>Subject: Re: [Tutor] CSV -> sqlite tables with foreign keys
>Message-ID:
>   
>Content-Type: text/plain; charset=UTF-8
>
>On Tue, Oct 16, 2012 at 11:59 PM, Monte Milanuk  wrote:
>>
>> address = list(row)
>> address.append(person)
>> row = tuple(address)
>
>The rows from the csv.reader are already lists. Also, the parameter
>list in the 2nd argument only needs to be a sequence (e.g. tuple,
>list, string), or it can also be a dict if the statement uses named
>placeholders.
>
>> from what I've found on the web, I get the distinct impression
>> that converting from a tuple to a list and back is considered
>> poor practice at best and generally to be avoided.
>
>To update a record in a tuple you can use slicing and concatenation
>(+) as an alternative to creating a temporary list.  A list is more
>applicable to homogenous data (e.g. a list of tuples, each a data
>record). If you want a container for a record that you can modify more
>efficiently, use a dict or a custom object. For the latter, look into
>ORMs such as Storm:
>
>https://storm.canonical.com/
>
>> Any suggestions?
>
>I found a Stack Overflow answer that uses a table "view" combined with
>an "instead of" trigger to update two tables with one insert.
>
>http://stackoverflow.com/a/11715983/205580
>
>Here's my meager attempt at an adaptation (some names have been
>changed to protect the innocent...):
>
>import csv
>import sqlite3
>
>con = sqlite3.connect(':memory:')
>cur = con.cursor()
>
>cur.execute('''create table person (
>  id integer primary key autoincrement,
>  firstname, midinit, lastname, birthdate)
>''')
>
>cur.execute('''create table address (
>  id integer primary key autoincrement,
>  person_id integer references person not null,
>  street, city, state, zipcode)
>''')
>
>cur.execute('''create view person_view as
>  select
>person.firstname, person.midinit, person.lastname,
>person.birthdate, address.street, address.city,
>address.state, address.zipcode
>  from
>person inner join address on person.id = address.person_id
>''')
>
>cur.execute('''create trigger person_view_insert
>  instead of insert on person_view
>  begin
>insert into
>  person (firstname, midinit, lastname, birthdate)
>  values (new.firstname, new.midinit, new.lastname,
>  new.birthdate);
>insert into
>  address (person_id, street, city, state, zipcode)
>  values ((select last_insert_rowid()),
>  new.street, new.city, new.state, new.zipcode);
>  end
>''')
>
>import io
>data = io.BytesIO(b'''\
>John,G.,Smith,1972-11-10,123 Any Place,Somewhere,Missouri,58932
>Jane,L.,Jones,1971-12-20,321 Some Place,Anywhere,Kansas,12345
>''')
>
>reader = csv.reader(data)
>for row in reader:
>cur.execute('''insert into
>  person_view (firstname, midinit, lastname, birthdate,
>   street, city, state, zipcode)
>  values (?,?,?,?,?,?,?,?)''', row)
>
># output
>for row in cur.execute('select * from person'):
>print row
>for row in cur.execute('select * from address'):
>print row
>
>
>person table:
>
>(1, u'John', u'G.', u'Smith', u'1972-11-10')
>(2, u'Jane', u'L.', u'Jones', u'1971-12-20')
>
>address table:
>
>(1, 1, u'123 Any Place', u'Somewhere', u'Missouri', u'58932')
>(2, 2, u'321 Some Place', u'Anywhere', u'Kansas', u'12345')
>
>
>--
>
>Message: 2
>Date: Wed, 10 Oct 2012 21:58:39 -0400
>From: Dwight Hutto 
>To: "Steven D'Aprano" 
>Cc: tutor@python.org
>Subject: Re: [Tutor] Why difference between printing string & typing
>   its object reference at the prompt?
>Message-ID:
>   
>Content-Type: text/plain; charset=ISO-8859-1
>
>If your app has  a standard usage of phr

Re: [Tutor] Python incrementing problem

2012-10-17 Thread eryksun
On Thu, Oct 11, 2012 at 3:29 PM, Stephen Hooker  wrote:
>
> I try to store 1 result it works fine. If I try to store more than 1 result
> I get one or the other, never both. The code is below (not the whole
> program)
>
> for i in range(2):
> pos = random.randrange(0,len(rolling_stock_OS))
> pick = rolling_stock_OS[pos]
> for item in noDupes:
> if item==pick:
> break
> else: # else for the loop, executed if the loop ran to exhaustion
> noDupes.append(pick)

The formatting was lost, but it seems you're trying to use two for
loops to do something that's easier with a single while loop, and even
easier if you take a random.sample() of a set():

http://docs.python.org/release/2.6.7/library/random.html#random.sample

>>> import random
>>> data = [3,1,4,5,9,3,1,4,5,9]
>>> random.sample(set(data), 5)
[9, 3, 5, 4, 1]
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Why VPython can't be searched out in PyPI?

2012-10-17 Thread Steven D'Aprano

On 17/10/12 19:23, Dae James wrote:

I found that VPython is not in PyPI(python packet index from
www.python.org). Why ?


You'd have to ask the author of VPython. Being on PyPI is not
compulsory, nobody is going to force him to use PyPI if he
doesn't want to.



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


Re: [Tutor] program for a problem

2012-10-17 Thread Mark Lawrence

On 08/10/2012 16:55, Tharuni Dheeraj wrote:

please send me the program for the following que:

Write a program that asks the user for a dollar amount.It then reports the
corresponding number of euros by using the current exchange rate.
--
Regards,
Tharuni Dheeraj



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



Please send me a cheque for £1000 sterling and I'll send you the program.

--
Cheers.

Mark Lawrence.

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


Re: [Tutor] managing memory large dictionaries in python

2012-10-17 Thread Steven D'Aprano

On 17/10/12 12:30, Dwight Hutto wrote:


My inexperienced advice would be to begin with the storage areas
available. I would begin by eliminating certain things such as:

x = {'one_entry' : 1}

into

x = {'one_entry':1}



Those two entries are exactly the same. The presence of absence of
spaces, or newlines, in the dict literal makes no difference to the
amount of memory that the dict will use.



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


Re: [Tutor] Consecutive Sequence

2012-10-17 Thread Dave Angel
On 10/13/2012 07:02 AM, syed zaidi wrote:
> Hi,I am trying to develop a python code that takes a character string as 
> input and  finds for the occurrence of letters that are occurring thrice or 
> more consecutively.For E.g.
> a = 'ataattaaacagagtgagcagt'In the output I want a list of those 
> characters that are occuring thrice or more.
> like in this case outout must b out_put = ['t','aaa','']
> Can someone please suggest a code for this.   
>   
>

Is this a homework assignment where you might be expected to build a
complex loop, or is it a problem you're solving where you would be
allowed to use itertools.groupby ?



-- 

DaveA

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


Re: [Tutor] Python Error

2012-10-17 Thread Dave Angel
On 10/05/2012 11:55 PM, Benjamin Lee wrote:
> Hello,
> I am using python to calculate distances across the cell. 
> I used this command:  python calculate_distances.py
> This was the response:
> Traceback (most recent call last):
> file "calculate_distances.py" line 4, in 
> import celltool.simple_interface as si
> ImportError: No module named celltool.simple_ interface
>
>
> I am not sure how to correct this error.
> Thank you for your time,
> Ben
>

celltool is not part of Python.

You tell us nothing about yourself or your system.  Did you write this
code (calculate_distances.py), or you trying to run someone else's
script?  If you downloaded it from somewhere, look there to see what its
dependencies are.  If you think you've installed the 'celltool" package,
you'll need to check where it ended up, and whether that place is on
your system.path.


-- 

DaveA

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


Re: [Tutor] Consecutive Sequence

2012-10-17 Thread eryksun
On Wed, Oct 17, 2012 at 8:02 AM, Dave Angel  wrote:
>
> Is this a homework assignment where you might be expected to build a
> complex loop, or is it a problem you're solving where you would be
> allowed to use itertools.groupby ?

May as well post a groupby solution. I doubt it would be accepted for homework:

>>> seq = 'ataattaaacagagtgagcagt'

>>> groups = (''.join(g) for _, g in groupby(seq))
>>> [g for g in groups if len(g) > 2]
['t', 'aaa', '']

groupby() yields (key, _grouper) tuples for each group in an iterable.
The default key function is lambda x: x. The _grouper objects share a
common iterator, so they need to be used in the order of creation.
Typically they're used immediately as the data pipes through. In the
generator expression, each _grouper g is joined into a string. The
list comprehension keeps strings of length greater than 2.

Alternatively, you can use a regular expression:

>>> [m.group() for m in re.finditer(r'(\w)\1{2,}', seq, re.U)]
['t', 'aaa', '']

\w matches an alphanumeric character or the underscore (the flag re.U
expands this to Unicode). The parentheses (round brackets) mark group
1, which is the single character matched by \w. Next, this group is
referenced with \1 with a repetition of {2,} (at least twice), for a
total of 3 or more consecutive occurrences.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] CSV -> sqlite tables with foreign keys

2012-10-17 Thread Monte Milanuk
Thanks for the help!  Not sure why I assumed that csv.reader was returning
row as a tuple instead of a list... that makes that part easier ;)

As for the 'INSTEAD OF' trigger on a VIEW... that *does* look pretty
handy.  I was trying to remember why I hadn't heard of that before, or why
I hadn't looked into it.  I think it has to do with MySQL not supporting
triggers on views, at least not 'INSTEAD OF'.  Right now I'm using sqlite,
but at some point I may need to work with MySQL as well.  It's getting kind
of frustrating how many little things it doesn't support...
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] program for a problem

2012-10-17 Thread bob gailer

On 10/8/2012 11:55 AM, Tharuni Dheeraj wrote:

please send me the program for the following que:

Write a program that asks the user for a dollar amount.It then reports 
the corresponding number of euros by using the current exchange rate.


As the list name (Tutor) suggests we are here to help you as you make 
effort and run into problems. Mark's response indicates that we will 
write code for you for pay.


If you want help, show us what you've done and where you are stuck.

Is this a homework assignment? How is one to obtain the "current 
exchange rate"?


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

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


Re: [Tutor] Tutor Digest, Vol 104, Issue 69

2012-10-17 Thread Alan Gauld

On 17/10/12 11:29, Cheng wrote:

I couldn't see any comment or question in there.
When posting could you please follow the instructions:



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



And also delete any irrelevant content. It makes it much easier for us 
to see what you are discussing/asking.


Oh yes, and while I'm at it, please post any comments after the context 
(in-line posting) it makes long threads much easier to follow.


Thanks,

--
Alan G
List moderator.

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


Re: [Tutor] Thread question

2012-10-17 Thread Steven D'Aprano

Mike,

A brief comment before I start:

your post would be a lot more readable and understandable if you were to
break it up into smaller paragraphs, each of which explains one point.
Otherwise it is a great wall of text which is fairly intimidating.


On 18/10/12 06:51, Mike wrote:


My program is command line based and is driven by the user making a
selection from the menu. Basically option 1 perform a HTTP GET request
to xyz.com/?get=test.  The user supply's a list  of target domains and
the query (?get=test) is static.


No it isn't. You go on to explain below that there are at least two
different queries:

?get=test
?get=check

and presumably no query at all (when param='').

Since the query is not static, but part of the request, it should be part
of the data pushed onto the queue. Instead of queuing just the domains,
queue a tuple (domain, query) or even the full URL.



This works great if the user selects option 1, but I am
running into problems when a user selects multiple options.  Say a
user selection 1 then option (2) with the targets being the same, but
the query string is now ?get=check. The problem I am facing is when
the threads run with option 1 and hit the initialization they are set
to ?get=test i.e. self.param=param. The param is passed in to the init
of the thread class.  When I initialize the class from option 1 I pass
in the param ?get=test and when I initialize the class with option 2 I
pass in the param ?get=check.  The default initialization is
self.param="".


Why is the query an attribute of the *thread*? The query is an attribute
of the request, not the thread.

Change your design, and the problem goes away.



Depending on which option they select first the thread
will be one of the following: blank, or one of the two options.  I
don't know how to update the thread variable when it's running i.e.def
run(self).


mythread.param = new_value

but please don't do this. The design is wrong, you have wrongly assumed
that the param is a part of the thread when it is actually a part of the
request.



I realize this sounds all confusing, but  I am basically
wondering how one would update a thread variable when it is running?
Also, is it best to spawn threads each time the user make a selection
or once when the program starts?


I would say, neither. It is best to spawn threads when they click the
"Make it go" button. Decide how many threads you need, spawn them, and
let them run.


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


[Tutor] Objects, object references, object values and memory addresses

2012-10-17 Thread boB Stepp
>From Programming in Python 3, 2nd edition (p. 22-23):

>>> a = ["Retention", 3, None]
>>> b = ["Retention", 3, None]
>>> a is b
False
>>> b = a
>>> a is b
True

My current understanding is as follows: On the first two lines, two
separate objects are defined, stored in two separate blocks of memory.
These two objects just happen to have the same value, ["Retention", 3,
None], stored in two separate locations. a and b, the object
references (Variables are what I used to call these.), store these two
separate memory locations. Thus a is b is false. However, when the
line b = a is implemented, b now references the same object (memory
location) as a, which now causes a is b to be true. Is my
understanding correct?

On the next page the author states (after giving a string example
where a and b each are assigned the string "many paths", similar to
the example above):

"In some cases, comparing the identity of two strings or numbers--for
example, using a is b--will return True, even if each has been
assigned separately as we did here. This is because some
implementations of Python will reuse the same object (since the value
is the same and is immutable) for the sake of efficiency..."

I ask: Which implementations of Python do this? In trying to make any
code I write portable across as many platforms as possible, should I
avoid using the identity operator, is (and its opposite, is not),
except when I wish to compare to None?

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


Re: [Tutor] Objects, object references, object values and memory addresses

2012-10-17 Thread Dave Angel
On 10/17/2012 11:41 PM, boB Stepp wrote:
> >From Programming in Python 3, 2nd edition (p. 22-23):
>
 a = ["Retention", 3, None]
 b = ["Retention", 3, None]
 a is b
> False
 b = a
 a is b
> True
>
> My current understanding is as follows: On the first two lines, two
> separate objects are defined, stored in two separate blocks of memory.
> These two objects just happen to have the same value, ["Retention", 3,
> None], stored in two separate locations. a and b, the object
> references (Variables are what I used to call these.), store these two
> separate memory locations. Thus a is b is false. However, when the
> line b = a is implemented, b now references the same object (memory
> location) as a, which now causes a is b to be true. Is my
> understanding correct?

You are correct, subject to an amendment.  Using the term memory
addresses implies a particular implementation.  CPython happens to work
that way, in its current implementation.  Jython happens not to.  No
biggie.  a and b are simply bound to two different objects, and it's
that difference that causes a false result.  When they're bound to the
same object, you get a true result.

>
> On the next page the author states (after giving a string example
> where a and b each are assigned the string "many paths", similar to
> the example above):
>
> "In some cases, comparing the identity of two strings or numbers--for
> example, using a is b--will return True, even if each has been
> assigned separately as we did here. This is because some
> implementations of Python will reuse the same object (since the value
> is the same and is immutable) for the sake of efficiency..."
>
> I ask: Which implementations of Python do this? In trying to make any
> code I write portable across as many platforms as possible, should I
> avoid using the identity operator, is (and its opposite, is not),
> except when I wish to compare to None?
>

Not just comparing to None, but to any singleton object.  if you're sure
that you have only one instance of a particular object, for whatever
reason, then it's safe to use 'is' to distinguish this object from any
other object.

Which implementations do this?  Any of them, starting with CPython,
which is probably the one you're using.  Note that mutable objects that
are different must be distinct, so each time you create one you'll get a
unique object.  It's only for immutable objects that the implementation
may decide to reuse existing objects.  This includes, ints, floats,
strings, byte strings, tuples, etc.  In the particular case of CPython,
small integers are cached in this way, and so are short strings with no
whitespace.  How small, and exactly which strings is irrelevant to me,
and hopefully to you.  The point is you cannot be sure whether equal
immutable objects are really just a single one, or not.

If you only care about value, then definitely use == or its variants. 
If you are comparing against a singleton, then go ahead and use 'is'. 
Otherwise, beware, and expect the unexpected.



-- 

DaveA

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