Python OpenSSL library
I am looking for Python OpenSSL library, for Python version 2.5.4 (on Windows) Which does not require to install Cygwin package. Need just to decrypt file, then uninstall library. -- http://mail.python.org/mailman/listinfo/python-list
Re: Python OpenSSL library
"Michael Crute" wrote in message news:[email protected]... > On Sun, Jun 13, 2010 at 4:29 PM, astral > wrote: > > I am looking for Python OpenSSL library, for Python version 2.5.4 (on > > Windows) > > Which does not require to install Cygwin package. Need just to decrypt file, > > then uninstall library. > > You might want to take a look at m2crypto[0]. While I have not > personally run it on Windows (runs great on OS X and Linux) they do > provide pre-compiled Windows binaries. > > [0] http://chandlerproject.org/bin/view/Projects/MeTooCrypto > > > -- > Michael E. Crute > http://mike.crute.org > > It is a mistake to think you can solve any major problem just with > potatoes. --Douglas Adams which one is for windows, for Python version 2.5.4 ? And how to uninstall when required? -- http://mail.python.org/mailman/listinfo/python-list
Python Programming Challenges for beginners?
Hi- I am reading the online tutorial along with a book I bought on Python. I would like to test out what I know so far by solving programming challenges. Similar to what O'Reilly Learning Perl has. I really enjoyed the challenges at the end of the chapter and it really help me test out if I was truly taking in the material like I should. Could I get some suggestions on resources? Is there anywhere where I can go online (for free or purchase) for programming problems? I am familiar with sites like Code Chef...etc...but at this stage that is not the right 'venue' for me. I mainly need challenges like the ones they have in Learning Perl. Thanks again for all the help, 457r0 -- http://mail.python.org/mailman/listinfo/python-list
Beginning Question about Python functions, parameters...
Hi, I am trying to teach myself Python and have a good book to help me
but I am stuck on something and I would like for someone to explain
the following piece of code for me and what it's actually doing.
Certain parts are very clear but once it enters the "def store(data,
full_name): " function and the "def lookup()..." function things
get a little confusing for me. Specifically, lines 103-108 *and* Lines
110-111.
Lastly, I am not sure how to print the results I've put into this
program either, the book I'm reading doesn't tell me. As you can tell,
I am a beginner and I don't truly understand everything that is going
on here...a lot, but not all
Here is the code:
92 def init(data):
93 data['first'] = {}
94 data['middle'] = {}
95 data['last'] = {}
96
97 def store(data, full_name):
98 names = full_name.split()
100 if len(names) == 2: names.insert(1, '')
101 labels = 'first', 'middle', 'last'
103 for label, name in zip(labels, names):
104 people = lookup(data, label, name)
105 if people:
106 people.append(full_name)
107 else:
108 data[label][name] = [full_name]
109
110 def lookup(data, label, name):
111 return data[label].get(name)
112
113
114 MyNames = {}
115 init(MyNames)
116 store(MyNames, 'John Larry Smith')
117 lookup(MyNames, 'middle', 'Smith')
--
http://mail.python.org/mailman/listinfo/python-list
Re: Beginning Question about Python functions, parameters...
On Nov 23, 1:17 pm, "Diez B. Roggisch" wrote:
> astral orange wrote:
> > Hi, I am trying to teach myself Python and have a good book to help me
> > but I am stuck on something and I would like for someone to explain
> > the following piece of code for me and what it's actually doing.
> > Certain parts are very clear but once it enters the "def store(data,
> > full_name): " function and the "def lookup()..." function things
> > get a little confusing for me. Specifically, lines 103-108 *and* Lines
> > 110-111.
>
> > Lastly, I am not sure how to print the results I've put into this
> > program either, the book I'm reading doesn't tell me. As you can tell,
> > I am a beginner and I don't truly understand everything that is going
> > on here...a lot, but not all
>
> > Here is the code:
>
> > 92 def init(data):
> > 93 data['first'] = {}
> > 94 data['middle'] = {}
> > 95 data['last'] = {}
> > 96
> > 97 def store(data, full_name):
> > 98 names = full_name.split()
> > 100 if len(names) == 2: names.insert(1, '')
> > 101 labels = 'first', 'middle', 'last'
> > 103 for label, name in zip(labels, names):
>
> The zip-function takes n iterables, and produces a list with n-tuples out of
> it. Type this into the python-prompt:
>
> >>> zip([1, 2, 3], ["a", "b", "c"])
>
> The other thing here is tuple-unpacking. If you know that something has a
> specific length, you can unpack it into distinct values like this:
>
> >>> a, b = (10, 20)
> >>> print a
> 10
> >>> print b
>
> 20
>
> Now
>
> for label, name in zip(labels, names):
>
> does
>
> - create a list of tuples, each tuple having two elements, the first being
> the label, the second a name
> - loops over this list
> - for each item in the list (remember, it's a 2-tuple!), unpack it into
> label and name
>
> > 104 people = lookup(data, label, name)
> > 105 if people:
> > 106 people.append(full_name)
> > 107 else:
> > 108 data[label][name] = [full_name]
> > 109
> > 110 def lookup(data, label, name):
> > 111 return data[label].get(name)
>
> Data here is expected to be a dictionary of dictionaries. The first level of
> keys are the labels. The second is the name. It is expected that labels
> always exist, but names might be empty, so instead of writing
>
> return data[label][name]
>
> it uses get(name) on a dict which will return the value for the key, or
> None:
>
>
>
> >>> {"foo" : "bar"}.get("foo")
> bar
> >>> {"foo" : "bar"}.get("baz")
> >>> # no output means None
>
> That being said, I agree with Neo that this introduction seems to be rather
> bad.
>
> Diez
Thanks all for the replies back! I do appreciate it.
Yes, lines 104-111 is really where my problem lies in understanding
what is going on here.
I am beginner so this stuff seems a little unwieldy at the moment. :)
I *did* invest $40
into this book so it' what I have to work with. By the way, the book
is, "Apress Beginning Python 2nd Edition"
But back to the example, on line 104 I see there's a call to the
lookup function, passing 3
parameters ('data', which I think is a nested dictionary, label
(first, middle, last) and name).
But I am getting lost on line 111 after the parameters are passed in
to the lookup function. I'm
not exactly sure what it's returning and when it does return, is this
assigned the the variable
'people'? And if so, I'm not sure what 'append(full_name)' does here.
The else statement which assigns
'[full_name]' to 'data[label][name]' is somewhat confusing as I'm
saying to myself where the heck did
'[full_name]' come "into the picture".
If I could understand what's going on with everything in this the rest
of the chapter and the next
should be fairly easy, but I really need to understand this before I
move on. Thanks again for the
replies back. I am looking over your comments right now.
457r0
--
http://mail.python.org/mailman/listinfo/python-list
Re: Beginning Question about Python functions, parameters...
On Nov 23, 4:35 pm, Terry Reedy wrote:
> astral orange wrote:
> > Yes, lines 104-111 is really where my problem lies in understanding
> > what is going on here.
> > I am beginner so this stuff seems a little unwieldy at the moment. :)
> > I *did* invest $40
>
> Water under the bridge. Focus on the future...
>
> > into this book so it' what I have to work with. By the way, the book
> > is, "Apress Beginning Python 2nd Edition"
>
> The online tutorial is free. Read it along with the book. Two
> explanations of a particular point are often better than one, at least
> for me.
>
> Now, to where you seem to be stuck. Data is a dict of 3 dicts, one for
> each part of a full [Western] name. Each subdict maps pieces of
> fullnames to a list of fullnames that contain that piece in the
> appropriate position.
>
> This is something like a database of names with 3 fields and an index
> for each field pointing to records in the database, except that there is
> no database. This is why the structure strikes people as a bit strange.
> The records are still there, off in anonymous dataspace, but there is no
> way to access them except via the indexes. If init started with
> data['names'] = [] # empty list, not dict
> and the third line of store were
> data['names'].append(names)
> then there would be. You might try that as an exercise once you
> understand what is already there.
>
> Anyway, you should "print MyNames" (2.x) or "print(MyNames)" (3.x) after
> storing the first name so you can see the structure of MyNames. The
> tutorial, of course, tells you this. DO read it.
>
> Then add more data and print again to see what changes. For instance,
>
> store(MyNames, 'Susan Smith')
> print(MyNames)
>
> Then try several lookups.
>
> store() checks each of the pieces of a name to see whether or not it is
> already in the corresponding key dict. This is the "people =" line. The
> important point in lookup is that when dict d does not contain key k,
> d.get(k) returns None while the usual d[k]raises a KeyError. So lookup()
> always return something, even if just None. So 'people' is either None
> or an exiting list of names. In the latter case, the current full names
> is added to the list. In the former case, the name-piece is associated
> with a new list with one item.
>
> If this is still not clear, add print statements or print function
> statements at appropriate places inside the code for the store function.
> This is how many people clarify thier understanding of a function,
> including when debugging.
>
> Good luck.
>
> Terry Jan Reedy
Wow! First, thanks Terry for the detailed explanation. I'll spend
the rest of the night trying to figure all of this out. :) Also,
thanks to everyone
else that responded as well. I do appreciate you all volunteering your
time to help.
I should of came here sooner.
As far as the program. I did add print statements such as print
(MyNames) and got back:
{'middle': {}, 'last': {'Smith': ['John Larry Smith']}, 'first': {}}
'Smith': ['John Larry Smith'] was in the last key so I will spend some
time figuring
out just why that is the case. I'll spend more time working with the
functions and
hopefully figure this out soon.
Thanks again!
Thanks again for the responses. I'll take all your advice.
--
http://mail.python.org/mailman/listinfo/python-list
Re: Beginning Question about Python functions, parameters...
On Nov 23, 10:37 pm, r wrote: > On Nov 23, 11:19 am, astral orange <[email protected]> wrote: > > > > > Hi, I am trying to teach myself Python and have a good book to help me > > but I am stuck on something and I would like for someone to explain > > the following piece of code for me and what it's actually doing. > > Certain parts are very clear but once it enters the "def store(data, > > full_name): " function and the "def lookup()..." function things > > get a little confusing for me. Specifically, lines 103-108 *and* Lines > > 110-111. > > > Lastly, I am not sure how to print the results I've put into this > > program either, the book I'm reading doesn't tell me. As you can tell, > > I am a beginner and I don't truly understand everything that is going > > on here...a lot, but not all > > > Here is the code: > > > 92 def init(data): > > 93 data['first'] = {} > > 94 data['middle'] = {} > > 95 data['last'] = {} > > 96 > > 97 def store(data, full_name): > > 98 names = full_name.split() > > 100 if len(names) == 2: names.insert(1, '') > > 101 labels = 'first', 'middle', 'last' > > 103 for label, name in zip(labels, names): > > 104 people = lookup(data, label, name) > > 105 if people: > > 106 people.append(full_name) > > 107 else: > > 108 data[label][name] = [full_name] > > 109 > > 110 def lookup(data, label, name): > > 111 return data[label].get(name) > > 112 > > 113 > > 114 MyNames = {} > > 115 init(MyNames) > > 116 store(MyNames, 'John Larry Smith') > > 117 lookup(MyNames, 'middle', 'Smith') > > This is a horrible example to show noobs. I think the OP could better > understand this as a class EVEN though the OP may or may not know what > a class *is* yet. > > >>> class Name(): > > def __init__(self, first, middle, last): > self.first = first > self.middle = middle > self.last = last > > >>> name1 = Name('Guido', 'van', 'Rossum') > >>> name1.first > 'Guido' > >>> name1.middle > 'van' > >>> name1.last > 'Rossum' > >>> print name1 > > <__main__.Name instance at 0x029BFD78> > > This time we add a __str__ method, the result will speak louder than > words!! > > >>> class Name(): > > def __init__(self, first, middle, last): > self.first = first > self.middle = middle > self.last = last > def __str__(self): > return '%s %s %s' %(self.first, self.middle, self.last) > > >>> name2 = Name('Terry', 'J', 'Reedy') > >>> name2.first > 'Terry' > >>> name2.middle > 'J' > >>> name2.last > 'Reedy' > >>> print name2 > > Terry J Reedy > > See the difference in the print statements. Now lets have some real > fun and access each sub name by index haha! > > >>> class Name(): > > def __init__(self, first, middle, last): > self.first = first > self.middle = middle > self.last = last > def __str__(self): > return '%s %s %s' %(self.first, self.middle, self.last) > def __len__(self): > return 3 > def __getitem__(self, item): > if item == 0: > return self.first > elif item == 1: > return self.middle > elif item == 2: > return self.last > else: > raise IndexError("Index must be in range 0, 2") > > >>> name = Name('Joe', 'blow', 'scripter') > >>> name[0] > 'Joe' > >>> name[1] > 'blow' > >>> name[2] > 'scripter' > >>> len(name) > > 3 > > WOW, thats more info in a few lines than any tut i ever seen! I wish i > could have seen that in my initial days, could have save some > countless hours of confusion!!! Maybe i am in the wrong line of work? > > Should i keep going...? Yeah, I don't think the example in the book is the best for someone starting out. I still am "not getting" certain parts of the program so I think I'll move on in hopes that it will *not* came back to haunt me and the book (along with the online tutorial) will help me grab more of the basics of Python programming. As for the "class Name():" example above? Even though I haven't seen exactly what purpose 'self' serves yet I can follow and understand what is going on very easily, that helps out tremendously. Very clearly written...Thank you! And thanks again to everyone... -- http://mail.python.org/mailman/listinfo/python-list
