[Tutor] Join Python Global Meeting Sunday June 21 using VOIP - BerkeleyTIP

2009-06-20 Thread john_re
Join the friendly Python Global [& ALL FREE SW HW & CULTURE]
community Meeting:
this Sunday, June 21, using VOIP,
10A - 6P Pacific USA time [GMT - 8? 7? hours] =
 1P - 9P Eastern USA = 
 6P - 2A??? GMT  - Daylight savings correction? +7 hours?

at the BerkeleyTIP Global Free SW HW & Culture meeting
http://sites.google.com/site/berkeleytip/

CONNECT VIA VOIP (& IRC):
Join IRC channel #berkeleytip on freenode.net,
& we'll help get you connected on VOIP.
Have a VOIP headset.
http://sites.google.com/site/berkeleytip/remote-attendance

LOCAL MEETING NEW LOCATION:
Free speech cafe closed Sundays in summer.  Watch the BTIP local list for final 
in person UCB meeting location details:
http://groups.google.com/group/BerkTIP

GENERIC HOURLY SCHEDULE, &
MARK YOUR CALENDAR - NEXT 3 MEETINGS:
Sun June 21, Sat July 4, Sun July 19
http://sites.google.com/site/berkeleytip/schedule

Join the mailing list, introduce yourself, tell us what projects you are 
interested in, invite others to join your project:
BTIP-Global
http://groups.google.com/group/BerkTIPGlobal

=
HOT TOPICs:
Oracle owns OpenOffice & MySQL - What help is needed?
KDE 4 aps need work - especially Calendar?!
Open Hardware - Robotics?
POLL:  ** How about 2x per month Weekday Evening BTIP-Global Meetings? **
  1) The Wednesday & Thursday _after_ the BTIP weekend meetings?
  2) The Monday & Tuesday _before_ the BTIP weekend meetings?
  3) Other? Your suggestions? 
 - Join the mailing list & send in your opinions/thoughts/suggestions.

GROUP PROJECT - Asterisk VOIP conference server:
We've now got our own Asterisk VOIP conference server. 
[Thanks, Windsor & Jack!  :)  ]
Help:
 - get a user channel members status page working
 - get SIP & Skype ability?
http://sites.google.com/site/berkeleytip/remote-attendance


YOUR PROJECT - LET US KNOW, GET SOME VOLUNTEER HELP:
http://groups.google.com/group/BerkTIPGlobal


VIDEOS - OPPORTUNITY - FINDER VOLUNTEER NEEDED
No videos this month, cause David & I are too busy.  Do you want to find some 
for us all to watch?  Check out this link, email the list & let us know you'd 
like to volunteer. :)
http://sites.google.com/site/berkeleytip/talk-videos

See the mailing lists for the latest info/changes:
http://sites.google.com/site/berkeleytip/mailing-lists

JOIN THE ANNOUNCEMENT LIST - 1 or 2 announcements per month:
http://groups.google.com/group/BerkTIPAnc


FOR FORWARDING:
You are invited to forward this message to anywhere appropriate.
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Generating Deck Combinations

2009-06-20 Thread Michael Morrissey
I need to generate all possible deck combinations given two different lists
as input.

The Input:

List 1 has Card names listed inside it.
List 2 has Maximum Quantities for each Card name.

For example:

List1[0] would be: "Aether Vial"
List2[0] would be: "4"

List1[1] would be: "Mountain"
List2[1] would be: "10"

List1[2] would be: "Gempalm Incinerator"
List2[2] would be: "3"

etc.


A deck is 60 cards total (no more, no less). I need to loop over these lists
to generate all possible combinations of 60 card decks which use up to the
maximum quantity for each card.

So, from the example, I need to generate decks with '1' Aether Vial' and 59
other cards in all possible combinations (still within the maximum cap for
each card), and then I'd need to generate decks with '2' Aether Vial' and 58
other cards in all possible combinations

It is vital that I create all combinations and that the maximum quantities
are never breached.

I am hoping that the each deck could be output as two lists:

ListA = ['Cardname1', 'Cardname2', ...]
ListB = ['1', '2', ...]

These lists will have exactly 60 members.

If you have an idea of how to do this, please share it! =) I would be most
appreciative. I'll be testing all methods for speed because I have very
large amount of computing to do.
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] how to manage an encrypted file?

2009-06-20 Thread Tim Golden

Robert Lummis wrote:

Could you recommend a module or methods I should use to manage an
encrypted text file? I want to store passwords and associated contact
information in a file and feel confident that if the file is stolen
the information couldn't be read.



If you're on Windows, just encrypt the file under Explorer.

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


Re: [Tutor] Generating Deck Combinations

2009-06-20 Thread Andre Engels
On Sat, Jun 20, 2009 at 9:49 AM, Michael Morrissey wrote:
> I need to generate all possible deck combinations given two different lists
> as input.
> The Input:
> List 1 has Card names listed inside it.
> List 2 has Maximum Quantities for each Card name.
>
> For example:
>
> List1[0] would be: "Aether Vial"
> List2[0] would be: "4"
>
> List1[1] would be: "Mountain"
> List2[1] would be: "10"
>
> List1[2] would be: "Gempalm Incinerator"
> List2[2] would be: "3"
>
> etc.

In my opinion, that's a very unpythonic way of specifying data - I
would use a dictionary for this kind of information:

maximalQuantity = {"Aether Vial": 4, "Mountain": 10, "Gempalm
Incinerator": 3 ...}

> A deck is 60 cards total (no more, no less). I need to loop over these lists
> to generate all possible combinations of 60 card decks which use up to the
> maximum quantity for each card.
> So, from the example, I need to generate decks with '1' Aether Vial' and 59
> other cards in all possible combinations (still within the maximum cap for
> each card), and then I'd need to generate decks with '2' Aether Vial' and 58
> other cards in all possible combinations
> It is vital that I create all combinations and that the maximum quantities
> are never breached.
> I am hoping that the each deck could be output as two lists:
> ListA = ['Cardname1', 'Cardname2', ...]
> ListB = ['1', '2', ...]
> These lists will have exactly 60 members.
> If you have an idea of how to do this, please share it! =) I would be most
> appreciative. I'll be testing all methods for speed because I have very
> large amount of computing to do.

Given that ListB will _always_ be ['1', '2', '3', ..., '60'], I do not
see what its use is...

For this problem I would use recursion. I define a function

possible_decks(listA, listB, number)

its input are the lists listA and listB and the number of cards in the
deck, its output is a list of lists, each of which is ListA (it is
confusing to have the same name for two different objects in your
description...) for some legal deck.

The code would be (untested):

def possible_decks(listA, listB, number):
if number < 0:
return [] # trying to put more than 60 cards in the deck
if number == 0:
return [[]] # there's exactly one deck of size 0 - the empty deck
if not listA:
return [] # out of cards, but the deck is not yet full
thiselement = listA[0]
thismaximum = int(listB[0])
returnvalue = []
for i in xrange(thismaximum):
 possible_rests_of_deck = possible_decks(listA[1:], listB[1:],
number - i)
 returnvalue += [i*[thiselement] + deck for deck in
possible_rests_of_deck]
return returnvalue

-- 
André Engels, andreeng...@gmail.com
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] how to manage an encrypted file?

2009-06-20 Thread Alan Gauld
"Tim Golden"  wrote 


encrypted text file? I want to store passwords and associated contact
information in a file and feel confident that if the file is stolen
the information couldn't be read.


If you're on Windows, just encrypt the file under Explorer.


Although that's not very secure: if you copy it to a non NTFS 
filesystem since Windows will, by default, helpfully unencrypt 
it for you...


There is some stuff on MSDN that tells how to make Windows 
encryption work sensibly but the defaults make it kind of pointless.
(Actually, I haven't tried this on XP, but certainly on Win2000 
the default encryption was a joke. If anyone can confirm that XP 
fixes it I might start using it again.)


Alan G.

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


Re: [Tutor] Generating Deck Combinations

2009-06-20 Thread Kent Johnson
On Sat, Jun 20, 2009 at 3:49 AM, Michael Morrissey wrote:
> I need to generate all possible deck combinations given two different lists
> as input.
> The Input:
> List 1 has Card names listed inside it.
> List 2 has Maximum Quantities for each Card name.

I generally prefer a list of pairs to paired list. In this case I
would use a single list containing tuples of (card name, max
quantitiy).

> A deck is 60 cards total (no more, no less). I need to loop over these lists
> to generate all possible combinations of 60 card decks which use up to the
> maximum quantity for each card.

This cries out for a recursive solution  - pick a number of the first
card, then create all possible decks containing the remaining cards.
Here is one solution. It uses a generator function, so rather than
returning a list of all solutions, it creates an iterator that yields
solutions.

limits = [('A', 3), ('B', 2), ('C', 4)]

def deck(limits, size):
# Check for end condition
if size == 0 or not limits:
yield []
return

# The current card and its limit
card, cardMax = limits[0]

# The remaining cards
rest = limits[1:]

# For each possible number of the current card
for i in range(0, min(size, cardMax)+1):
cards = [card] * i

# Create all possible decks from the remaining cards
for remainder in deck(rest, size-i):
if size-i == len(remainder):
yield cards + remainder

for d in deck(limits, 5):
print d


There are probably faster ways but this is straightforward. One
inefficiency in this one is that it generates a lot of short solutions
that are screened out by the "if size-i == len(remainder)"
conditional. This conditional isn't hit until the full recursion is
completed. This could be optimized by creating a list of (card name,
max quantity, max quantity following). I.e. the third element is the
most cards that could be added from the remaining cards. If this is
less than size-i, then there is no need to continue, the deck can't be
completed.

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


Re: [Tutor] Generating Deck Combinations

2009-06-20 Thread Dave Angel



Michael Morrissey wrote:


I need to generate all possible deck combinations given two different lists
as input.

The Input:

List 1 has Card names listed inside it.
List 2 has Maximum Quantities for each Card name.

For example:

List1[0] would be: "Aether Vial"
List2[0] would be: "4"

List1[1] would be: "Mountain"
List2[1] would be: "10"

List1[2] would be: "Gempalm Incinerator"
List2[2] would be: "3"

etc.


A deck is 60 cards total (no more, no less). I need to loop over these lists
to generate all possible combinations of 60 card decks which use up to the
maximum quantity for each card.

So, from the example, I need to generate decks with '1' Aether Vial' and 59
other cards in all possible combinations (still within the maximum cap for
each card), and then I'd need to generate decks with '2' Aether Vial' and 58
other cards in all possible combinations

It is vital that I create all combinations and that the maximum quantities
are never breached.

I am hoping that the each deck could be output as two lists:

ListA = ['Cardname1', 'Cardname2', ...]
ListB = ['1', '2', ...]

These lists will have exactly 60 members.

If you have an idea of how to do this, please share it! =) I would be most
appreciative. I'll be testing all methods for speed because I have very
large amount of computing to do.
  
It isn't considered polite to submit questions without even attempting 
your own solutions.  And classroom assignments should be solved by the 
student. But I can give you some general hints.


Since you're doing combinations, not permutations, the usual approach of 
making a complete deck (containing all possible duplicates of cards), 
and doing selection without replacement won't run in practical time.


Consider writing a generator function (look up yield) that uses 
recursion to list all the cases.  Worst case recursion would be 59, of 
course.


Consider returning the results front loaded:
Aether Vial-4, Mountain-10, ...


Aether Vial-4, Mountain-9, ...

Aether Vial-4, Mountain-8, ...


.
Aether Vial-3, Mountain-10, ...


That way, the funny edge-cases are at the end, and you can just return 
the first time your recursion gets beyond the end of the ListA


While initial testing, pick a much smaller number than 60, like 6.  And 
of course use smaller numbers for ListB




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


Re: [Tutor] how to manage an encrypted file?

2009-06-20 Thread Wayne
On Sat, Jun 20, 2009 at 6:17 AM, Alan Gauld wrote:

> "Tim Golden"  wrote
>
>> encrypted text file? I want to store passwords and associated contact
>>> information in a file and feel confident that if the file is stolen
>>> the information couldn't be read.
>>>
>>
>> If you're on Windows, just encrypt the file under Explorer.
>>
>
> Although that's not very secure: if you copy it to a non NTFS filesystem
> since Windows will, by default, helpfully unencrypt it for you...
>
> There is some stuff on MSDN that tells how to make Windows encryption work
> sensibly but the defaults make it kind of pointless.
> (Actually, I haven't tried this on XP, but certainly on Win2000 the default
> encryption was a joke. If anyone can confirm that XP fixes it I might start
> using it again.)


I used a program called AxCrypt (  http://www.axantum.com/AxCrypt/ ) that
seemed to work alright.

If you want the most basic encryption you could simply XOR the file. It's
fairly easy to break, though, because the same character patterns will be
present as with your original file.

HTH,
Wayne


-- 
To be considered stupid and to be told so is more painful than being called
gluttonous, mendacious, violent, lascivious, lazy, cowardly: every weakness,
every vice, has found its defenders, its rhetoric, its ennoblement and
exaltation, but stupidity hasn’t. - Primo Levi
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Handling Generator exceptions in Python 2.5

2009-06-20 Thread Joe

Dave,

Thanks for enlightening me and providing a solution.
I am a recent Python convert (from Perl). Hence the confusion about 
generators.(Coroutines are not a standard part of Perl anyway)


- Joe


Dave Angel wrote:

Joe Python wrote:


I have a generator as follows to do list calculations.

*result = [(ListA[i] - ListB[i-1])/ListA[i] for i in range(len(ListA))]*

The above generator, throws '*ZeroDivisionError*' exception if 
ListA[i] =

0.
Is there a way to say 'Don't divide by ListA[i] if its equal to 0 
(within

that statement)'.

Sorry if this question sounds too stupid.

TIA
Joe

Doesn't sound stupid to me at all.

Short answer is a conditional expression. Replace
(ListA[i] - ListB[i-1])/ListA[i]
with
(ListA[i] - ListB[i-1])/ListA[i] if ListA[i] else 1.0

and you'll see 1.0 whenever ListA[i] == 0, and your original value 
otherwise.



But I see a couple of other things. You're calling this a generator 
when it's a list comprehension. For short lists, that frequently 
doesn't matter, but in case it does, you could start by replacing the 
braces on the outside with parentheses.


Next question is the two lists are the same length. And final one is 
whether you really meant the offset of one when accessing ListB. If 
the lists are both of length 4, you're doing something like

(a0 - b3)/a0 (a1-b0)/a1 (a2-b1)/a2 (a3-b2)/a3

In other words, you're using the last item of ListB for the first 
division.


If that's really what you want, consider the following generator:
gen = ((a-b)/a if a!=0.0 else 1.0 for a,b in zip(ListA, 
ListB[-1:]+ListB))



___
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] Generating deck combinations

2009-06-20 Thread Paul McGuire
If you are looking for all possible 60-card deals of this deck, then you
also probably want to filter out duplicate deals caused by equivalent cards
exchanging places.  That is, say you had a deck of 3 cards: 2 Mountain, and
1 Vial, and you want to deal out al 3 in various order of cards.  Using the
recursive solutions, you will get:

(hmm, couldn't get either of the previous submissions to work..., well
something like this)

['Mountain', 'Mountain', 'Vial']
['Mountain', 'Vial', 'Mountain']
['Mountain', 'Mountain', 'Vial']
['Mountain', 'Vial', 'Mountain']
['Vial', 'Mountain', 'Mountain']
['Vial', 'Mountain', 'Mountain']


That is, because you have 2 Mountain cards, recursively shuffling this list
*looks* like you have two different list elements to process, but in fact,
they are equivalent so you will get duplicate deals.

Now imagine you have up to 150 different types of cards, in quantities of
1-10 of each, and this problem magnifies considerably.

Try this version (mildly tested):

def deal(cards, size):
if size > len(cards):
raise ValueError, "cannot deal more cards than are in the deck"

if size == 1:
for cd in cards:
yield [cd]
else:
for i,cd in enumerate(cards):
remainder = cards[:i] + cards[i+1:]
for d in deal(remainder,size-1):
yield [cd]+d


cardlist = [('Mountain', 2), ('Vial', 6), ]
allcards = sum(([card,]*qty for card,qty in cardlist), [])

# generate all unique deals of 'n' cards from allcards
# use the seenalready set to avoid reporting duplicate deals
n = 4
seenalready = set()

for d in deal(allcards,n):
newdeck = tuple(d)
if newdeck not in seenalready:
print d
seenalready.add(newdeck)

Here are all the 4-card deals from this pack of 8 cards:

['Mountain', 'Mountain', 'Vial', 'Vial']
['Mountain', 'Vial', 'Mountain', 'Vial']
['Mountain', 'Vial', 'Vial', 'Mountain']
['Mountain', 'Vial', 'Vial', 'Vial']
['Vial', 'Mountain', 'Mountain', 'Vial']
['Vial', 'Mountain', 'Vial', 'Mountain']
['Vial', 'Mountain', 'Vial', 'Vial']
['Vial', 'Vial', 'Mountain', 'Mountain']
['Vial', 'Vial', 'Mountain', 'Vial']
['Vial', 'Vial', 'Vial', 'Mountain']
['Vial', 'Vial', 'Vial', 'Vial']

(If order is not significant, then you could simplify this algorithm
accordingly, and you would get these results:
['Mountain', 'Mountain', 'Vial', 'Vial']
['Mountain', 'Vial', 'Vial', 'Vial']
['Vial', 'Vial', 'Vial', 'Vial']
)

This is definitely a brute-force approach (brute-force is actually my
favorite first approach), generating all possible deals and then filtering
duplicates using a set of "already been seen" deals.  A smarter algorithm
would generate only the unique deals.  If someone were paying me to be that
smart, maybe I'd work on it.

I'm guessing this is an attempt to optimize a deck for playing a card game
like Magic or Pokemon, etc.  Your plan is, given a set of 'n' cards in your
collection (presumbaly n>60, or there would be no problem to solve), to
compute all possible decks of 60 cards.  Then you have some function to
evaluate this deck, or perhaps simulate playing it against another deck.
You will then exhaustively run this simulation function against each deck to
find which deck from your collection of 100's of cards is the "best".

By the time your program has finished running, I suspect the sun will be a
cold, dark cinder.  But have fun with it.

-- Paul

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


Re: [Tutor] Generating deck combinations

2009-06-20 Thread Kent Johnson
On Sat, Jun 20, 2009 at 1:01 PM, Paul McGuire wrote:
> If you are looking for all possible 60-card deals of this deck, then you
> also probably want to filter out duplicate deals caused by equivalent cards
> exchanging places.  That is, say you had a deck of 3 cards: 2 Mountain, and
> 1 Vial, and you want to deal out al 3 in various order of cards.  Using the
> recursive solutions, you will get:
>
> (hmm, couldn't get either of the previous submissions to work..., well
> something like this)
>
> ['Mountain', 'Mountain', 'Vial']
> ['Mountain', 'Vial', 'Mountain']
> ['Mountain', 'Mountain', 'Vial']
> ['Mountain', 'Vial', 'Mountain']
> ['Vial', 'Mountain', 'Mountain']
> ['Vial', 'Mountain', 'Mountain']

No, my solution does not generate that list. It generates
['Vial', 'Vial', 'Vial']
['Mountain', 'Vial', 'Vial']
['Mountain', 'Mountain', 'Vial']

> That is, because you have 2 Mountain cards, recursively shuffling this list
> *looks* like you have two different list elements to process, but in fact,
> they are equivalent so you will get duplicate deals.

My solution does not shuffle. It picks each possible number of the
first card, then recursively constructs all possible decks from the
remaining card .

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


[Tutor] filling in web forms

2009-06-20 Thread Pete Froslie
I would to access web forms and fill them out.

I am feeling that the 'ClientForm' module makes sense as a starting place,
but am concerned that maybe it is dated and that there might be a better
starting option.. can anyone help start me along the correct path as I am
pretty new to python and not the most experienced programmer?

thanks so much!

-- 
P Froslie
http://www.froslie.net
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] reading and processing xml files with python

2009-06-20 Thread python . list
Hi,
I am a total python XML noob and wanted some clarification on using python with 
reading remote XML data. 

All examples I have found assumes the data is stored localy or have I 
misunderstood this?

If I browse to:
'user:passw...@domain.com/external/xmlinterface.jsp?cid=xxx&resType=hotel200631&intfc=ws&xml='

This request returns a page like:


−

134388
Milford Plaza at Times Square
700 8th Avenue


New York
NY
US
10036
NYC
155.4
259.0
USD
40.75905
-73.98844
+

Location.
  • The Milford Plaza is located in New York, N.Y. /hotels/thumbs/NYC_MILF-exter-1-thumb.jpg H TIMES SQUARE/THEATER DISTRICT 2.5 1 1 true true 3.9202964 MI + N 72 Hour Sale - Don't miss this great deal! 17A828141014136319 -1 25033 true false Standard room 108606 252427 − USD − 259.0 259.0 575.76 575.76 57.76 USD − 259.0 259.0 575.76 B − USD − 155.4 155.4 368.56 368.56 57.76 USD − 155.4 155.4 368.56 B I got this so far: >>> import urllib2 >>> request = >>> urllib2.Request('user:passw...@domain.com/external/xmlinterface.jsp?cid=xxx&resType=hotel200631&intfc=ws&xml=') >>> opener = urllib2.build_opener() >>> firstdatastream = opener.open(request) >>> firstdata = firstdatastream.read() >>> print firstdata 134388 Milford Plaza at Times Square 700 8th Avenue New York NY US 10036 ... >>> I would like to understand how to manipulate the data further and extract for example all the hotel names in a list? Thank you Marti ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] filling in web forms

2009-06-20 Thread Norman Khine
On Sun, Jun 21, 2009 at 12:03 AM, Pete Froslie wrote:
> I would to access web forms and fill them out.
>
> I am feeling that the 'ClientForm' module makes sense as a starting place,
> but am concerned that maybe it is dated and that there might be a better
> starting option.. can anyone help start me along the correct path as I am
> pretty new to python and not the most experienced programmer?

You could try using twill http://twill.idyll.org/

The first example shows you how to fill out a login form.
http://twill.idyll.org/examples.html

>
> thanks so much!
>
> --
> P Froslie
> http://www.froslie.net
>
>
> ___
> Tutor maillist  -  tu...@python.org
> http://mail.python.org/mailman/listinfo/tutor
>
>
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] filling in web forms

2009-06-20 Thread Serdar Tumgoren
You might want to read up on Python Mechanize as well:

http://wwwsearch.sourceforge.net/mechanize/
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] filling in web forms

2009-06-20 Thread Pete Froslie
Thank you so much.. I will start looking into twill and I just finished
installing Mechanize.

FYI:

I use Netbeans as my IDE and encountered an error that took some time to
resolve, as follows:
A java.lang.NoClassDefFoundError exception has occurred

the resolution can be found here if you run into it:
http://forums.netbeans.org/post-38386.html

it seems to have been an issue with mac OS X : java 10.5 update 6.

with that fixed I'll be able to try these options out..



On Sun, Jun 21, 2009 at 1:03 AM, Serdar Tumgoren wrote:

> You might want to read up on Python Mechanize as well:
>
> http://wwwsearch.sourceforge.net/mechanize/
> ___
> 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] reading and processing xml files with python

2009-06-20 Thread Norman Khine
you can use something like http://docs.hforge.org/itools/xml.html to
process your xml request or some other python xml parser such as
BeautifulStoneSoup.

to return a list of the  tag value, you could , perhaps:

>>> firstdata = ' 134388 Milford Plaza at Times 
>>> Square 700 8th Avenue   
>>> New York NY 
>>> US 10036 '
>>>
>>> from itools.xml import (XMLParser, START_ELEMENT,
... END_ELEMENT, TEXT)
>>> names = []
>>> for type, value, line in XMLParser(firstdata):
... if type == TEXT:
... names.append(value)
>>> names
[' ', '134388', ' ', 'Milford Plaza at Times Square', ' ', '700 8th
Avenue', ' ', ' ', ' ', 'New York', ' ', 'NY', ' ', 'US', ' ',
'10036', ' ']

Here is a another version, using BeautifulStoneSoup:

>>> from BeautifulSoup import BeautifulStoneSoup
>>> soup = BeautifulStoneSoup(firstdata)
>>> names = soup.findAll('name')
>>> names
[Milford Plaza at Times Square]
>>>


On Sat, Jun 20, 2009 at 9:34 PM,  wrote:
> Hi,
> I am a total python XML noob and wanted some clarification on using python 
> with reading remote XML data.
>
> All examples I have found assumes the data is stored localy or have I 
> misunderstood this?
>
> If I browse to:
> 'user:passw...@domain.com/external/xmlinterface.jsp?cid=xxx&resType=hotel200631&intfc=ws&xml='
>
> This request returns a page like:
>
> 
> -
> 
> 134388
> Milford Plaza at Times Square
> 700 8th Avenue
> 
> 
> New York
> NY
> US
> 10036
> NYC
> 155.4
> 259.0
> USD
> 40.75905
> -73.98844
> +
> 
> Location.
  • The Milford Plaza > is located in New York, N.Y. > > /hotels/thumbs/NYC_MILF-exter-1-thumb.jpg > H > TIMES SQUARE/THEATER DISTRICT > 2.5 > 1 > 1 > true > true > 3.9202964 > MI > + > > N > 72 Hour Sale - Don't miss this great > deal! > > > 17A828141014136319 > -1 > 25033 > true > false > Standard room > 108606 > 252427 > - > > USD > - > > 259.0 > 259.0 > > 575.76 > 575.76 > 57.76 > USD > - > > 259.0 > 259.0 > > 575.76 > B > > - > > USD > - > > 155.4 > 155.4 > > 368.56 > 368.56 > 57.76 > USD > - > > 155.4 > 155.4 > > 368.56 > B > > > > > > I got this so far: > import urllib2 request = urllib2.Request('user:passw...@domain.com/external/xmlinterface.jsp?cid=xxx&resType=hotel200631&intfc=ws&xml=') opener = urllib2.build_opener() firstdatastream = opener.open(request) firstdata = firstdatastream.read() print firstdata > > > > >134388 >Milford Plaza at Times Square >700 8th Avenue > > >New York >NY >US >10036 > > ... > > > I would like to understand how to manipulate the data further and extract for > example all the hotel names in a list? > > Thank you > Marti > ___ > 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] filling in web forms

2009-06-20 Thread wesley chun
On Sat, Jun 20, 2009 at 10:25 PM, Pete Froslie wrote:
> Thank you so much.. I will start looking into twill and I just finished
> installing Mechanize.


those are very well-known individual tools that will meet your needs.
for larger web testing frameworks, you may also consider Windmill and
Selenium.

best regards,
-- wesley
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
"Python Web Development with Django", Addison Wesley, (c) 2009
http://withdjango.com

wesley.j.chun :: wescpy-at-gmail.com
python training and technical consulting
cyberweb.consulting : silicon valley, ca
http://cyberwebconsulting.com
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor