Re: [Tutor] 3 Dimensional Dictionaries

2013-07-20 Thread Dominik George
Hi,

> world =
> [{'continent':'Asia','continent_code':1,'ocean':'Pacific','country':'India','country_code':1,'state':'Kerala',
> 'state_pin':51},
>  [...]
> 
> i am trying to to make it in this format
> 

to clarify the task at hand: this is comparible to SQL's GROUP BY
clause, right?

-nik

-- 
 Auf welchem Server liegt das denn jetzt…?
 Wenn es nicht übers Netz kommt bei Hetzner, wenn es nicht
gelesen wird bei STRATO, wenn es klappt bei manitu.

PGP-Fingerprint: 3C9D 54A4 7575 C026 FB17  FD26 B79A 3C16 A0C4 F296


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


Re: [Tutor] slashes in paths

2013-07-20 Thread Dominik George
Hi,

> >>> soundfile13
> 'c:/python27/jimprogs/wav\\bicycle_bell.wav'
> >>>
> 
> with single forward slashes mixed with a double backslash
> 
> it comes out even worse if I print it
> 
> c:/python27/jimprogs/wav\bicycle_bell.wav  - no double backslash,
> which could create a mess if someone copied that and tried it.

That's because the interactive python interpreter has bad behaviour when
you just throw a name at it. It tries to find a good trade-off between
exact representation of the internal data and human readibility. The
result you see is printed in such a way that you can copy and paste it
as a Python string, with escaped backslashes.

When you use print, the human-readable string data is written to stdout,
with the literal backslashes that the string really contains.

> Oddly, the mixed path does work for playing sounds,
> 
> >>> import winsound
> >>> winsound.PlaySound('c:/python27/jimprogs/wav\\bicycle_bell.wav',winsound.SND_FILENAME)
> >>>
> That rings a bell.

This will work in any case. First of all, in this example code, the \\
creates a literal backslash in the string, so what is used in the end is
a single backslash. If that weren't the case, this would still work
because empty directory names are ignored in all reasonable operating
systems.

> But it just doesn't look right. If forward slash is a Python
> convention instead of double backslash, it should follow through. I
> can see where you could get in trouble with it.

Well, who says it is a Python convention? It is a POSIX convention, and
in your code above you jsut used that. Because Python is such a good
friend, it doesn't blow up but take what you gave to it. As you can see
by using the os.path.join() function is that on Windows, when you ask
Python to do the work for you, it really uses *single* backslashes.

-nik

-- 
 Ein Jabber-Account, sie alle zu finden; ins Dunkel zu treiben
und ewig zu binden; im NaturalNet, wo die Schatten droh'n ;)!

PGP-Fingerprint: 3C9D 54A4 7575 C026 FB17  FD26 B79A 3C16 A0C4 F296


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


Re: [Tutor] slashes in paths

2013-07-20 Thread Dominik George
Hi Jim,

> But oddly, it makes all slashes forward if I end the path with a
> forward slash, so it's not consistent with itself.

It is, in the sense that it preserves any form of seperator that is
already there. It just doesn't throw away what you want to be there:

 >>> import ntpath
 >>> ntpath.join("a", "b")
 'a\\b'
 >>> ntpath.join("a/", "b")
 'a/b'
 >>> ntpath.join("a/", "b", "c")
 'a/b\\c'
 >>> 

"Explicit is better than implicit", so if you explicitly require it to
use a certain seperator it uses it. If you don't, it implie the
OS-native seperator. Remember that Windows NT is alright with forward
slashes, even outside Python, so it is ok to preserve it if it is
already there.

(On a side note, I imported ntpath to force the NT pathname behaviour on
my Linux Python. os.path always matches the *path module for the current
OS, so there is no difference there.)

> BTW, is ending a path with a slash a Linux requirement, or just a
> convention, or a who-cares-either-way? I forget since I've been on
> windows a long time, and it accepts either method. I guess the best
> thing is to always end all paths with a forward slash, catching both
> OS's and being consistent.

It is a POSIX convention. I think a POSIX OS is allowed to rais ENOENT
if you leave the last slash out when referencing a directory, but most
shells and programs imply it.

-nik

-- 
 Auf welchem Server liegt das denn jetzt…?
 Wenn es nicht übers Netz kommt bei Hetzner, wenn es nicht
gelesen wird bei STRATO, wenn es klappt bei manitu.

PGP-Fingerprint: 3C9D 54A4 7575 C026 FB17  FD26 B79A 3C16 A0C4 F296


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


Re: [Tutor] slashes in paths

2013-07-20 Thread Dominik George
Hi,

the base path is \, and one exists for every drive. C:\foo is foo in C:'s root, 
C:foo is foo in C:'s current working directory.

-nik



Jim Mooney  schrieb:

>On 20 July 2013 13:46, Alan Gauld  wrote:
>
>> The fact that you gave it a prefix containing forward
>> slashes is confusing things. It works best with a list
>> of individual folder names and let it provide the os.sep.
>> Try splitting your partial path before feeding it to join.
>
>Except I can't do that with 'C:' since the docs stay that on windows,
>only 'c:/' is accepted as the base path, not 'c:'.
>
>If only Bill Gates hadn't chosen '\', which is awkward to type and
>hard to make compatible - but I think he figured his wonderful DOS
>would be a Unix-killer, reign supreme, and there would be no
>compatibility problem. All I can say to that is, "thank God for
>competition."  ;')
>
>Jim
>
>At one time if someone had a lame idea,  you'd say, "That and ten
>cents will get you a cup of coffee."   Now you have to say, "That and
>five dollars and forty-eight cents will get you a double
>creme-de-menthe Grande frappe, with a touch of juniper, nonfat creme,
>and low on the sugar."
>
>It just ain't the same.
>___
>Tutor maillist  -  Tutor@python.org
>To unsubscribe or change subscription options:
>http://mail.python.org/mailman/listinfo/tutor

-- 
Diese Nachricht wurde von meinem Android-Mobiltelefon mit K-9 Mail gesendet.___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] re module- puzzling results when matching money

2013-08-03 Thread Dominik George
Hi,

\b is defined as all non-word characters, so it is the complement oft \w. \w is 
[A-Za-z0-9_-], so \b includes \$ and thus cuts off your  group.

-nik



Alex Kleider  schrieb:
>#!/usr/bin/env python
>
>"""
>I've been puzzling over the re module and have a couple of questions
>regarding the behaviour of this script.
>
>I've provided two possible patterns (re_US_money):
>the one surrounded by the 'word boundary' meta sequence seems not to
>work
>while the other one does. I can't understand why the addition of the
>word
>boundary defeats the match.
>
>I also don't understand why the split method includes the matched text.
>Splitting only works as I would have expected if no goupings are used.
>
>If I've set this up as intended, the full body of this e-mail should be
>executable as a script.
>
>Comments appreciated.
>alex kleider
>"""
>
># file :  tutor.py (Python 2.7, NOT Python 3)
>print 'Running "tutor.py" on an Ubuntu Linux machine. *'
>
>import re
>
>target = \
>"""Cost is $4.50. With a $.30 discount:
>Price is $4.15.
>The price could be less, say $4 or $4.
>Let's see how this plays out:  $4.50.60
>"""
>
># Choose one of the following two alternatives:
>re_US_money =\
>r"((?P\$)(?P\d{0,})(?:\.(?P\d{2})){0,1})"
># The above provides matches.
># The following does NOT.
># re_US_money =\
># r"\b((?P\$)(?P\d{0,})(?:\.(?P\d{2})){0,1})\b"
>
>pat_object = re.compile(re_US_money)
>match_object = pat_object.search(target)
>if match_object:
> print "'match_object.group()' and 'match_object.span()' yield:"
> print match_object.group(), match_object.span()
> print
>else:
> print "NO MATCH FOUND!!!"
>print
>print "Now will use 'finditer()':"
>
>print
>iterator = pat_object.finditer(target)
>i = 1
>for iter in iterator:
> print
> print "iter #%d: "%(i, ),
> print iter.group()
> print "'groups()' yields: '%s'."%(iter.groups(), )
> print iter.span()
> i += 1
> sign = iter.group("sign")
> dollars = iter.group("dollars")
> cents = iter.group("cents")
> print sign,
> print "  ",
> if dollars:
> print dollars,
> else:
> print "00",
> print "  ",
> if cents:
> print cents,
> else:
> print "00",
>
>print
>
>t = target
>sub_target = pat_object.sub("", t)
>print
>print "Printing substitution: "
>print sub_target
>split_target = pat_object.split(target)
>print "Result of splitting on the target: "
>print split_target
>
># End of script.
>___
>Tutor maillist  -  Tutor@python.org
>To unsubscribe or change subscription options:
>http://mail.python.org/mailman/listinfo/tutor

--
Diese Nachricht wurde von meinem Android-Mobiltelefon mit K-9 Mail gesendet.___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] re module- puzzling results when matching money

2013-08-04 Thread Dominik George
Hi,

not quite. The moral is to learn about greedy and non-greedy matching ;)!

-nik



Alex Kleider  schrieb:
>On 2013-08-03 13:38, Dominik George wrote:
>> Hi,
>> 
>>  b is defined as all non-word characters, so it is the complement oft
>> w. w is [A-Za-z0-9_-], so b includes $ and thus cuts off your 
>> group.
>> 
>>  -nik
>
>I get it now.  I was using it before the '$' to define the beginning of
>
>a word but I think things are failing because it detects an end of
>word.
>Anyway, the moral is not to use it with anything but \w!
>
>Thanks!

-- 
Diese Nachricht wurde von meinem Android-Mobiltelefon mit K-9 Mail gesendet.___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] LDAP search with ldap library module failing

2013-08-05 Thread Dominik George
Hi,

> Now, if I search fog cn=ab*, a much limited search it will return the search
> results. Thinking that it could be a limitation from the server side, I've 
> done
> the same search with ldapsearch in bash, and it gets what is expected.

Are you sure it gets what is expected? ldapsearch limits the results to
500 - maybe the LDAP library does not. How many entries do you expect?

> I am using ipython, and python 2.6 in a linux OS.

Why are you using such an outdated version? Any chance you upgrade to
Python 2.7?

> My question is: How can I try to debug this issue?

There are several ways, Two are reading the LDAP server logs, and
tcpdumping the connection to see if anything happens. I am pretty
certain that this is not an issue with your code.

> The error message is: ('EOF in multi-line statement', (379, 0))

> --> 519 return 
> self.search_ext_s(base,scope,filterstr,attrlist,attrsonly,None,None,timeout)

This is why I say "never use ipython". The error message is complete
non-sense.

-nik

-- 
* concerning Mozilla code leaking assertion failures to tty without D-BUS *
 That means, D-BUS is a tool that makes software look better
than it actually is.

PGP-Fingerprint: 3C9D 54A4 7575 C026 FB17  FD26 B79A 3C16 A0C4 F296


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


Re: [Tutor] How to extract numerator and denominator from fractions.Fraction(4, 32)?

2013-08-05 Thread Dominik George
Hi,

how about casting to str()?

-nik



"Richard D. Moores"  schrieb:
 import fractions
 fractions.Fraction(6, 21)
>Fraction(2, 7)
>
>How do I turn that Fraction(2, 7) into "1/7"? (and not
>0.2857142857142857...)
>
>Or do I have to employ fractions.gcd?
>
>I can't seem to find the answer in the doc at
>
>
>Thanks,
>
>DIck Moores
>___
>Tutor maillist  -  Tutor@python.org
>To unsubscribe or change subscription options:
>http://mail.python.org/mailman/listinfo/tutor

-- 
Diese Nachricht wurde von meinem Android-Mobiltelefon mit K-9 Mail gesendet.___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] os.system() not working

2013-08-27 Thread Dominik George
Hi,

in any case and apart from what was already said, your setup sounds very 
awkward, if not insane.

Are you sure your implementation is a good idea?

-nik



Nitish Kunder  schrieb:
>Hii
>I have a python program which i am calling from a php script.
>The arguments to the program is a path to the file
>The program when directly run from console executes normally.
>But when I try to execute the program from browser ie call the python
>script from php,
>os.system command is not working what might be the problem.
>Thanks
>
>
>
>
>___
>Tutor maillist  -  Tutor@python.org
>To unsubscribe or change subscription options:
>http://mail.python.org/mailman/listinfo/tutor

-- 
Diese Nachricht wurde von meinem Android-Mobiltelefon mit K-9 Mail gesendet.___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Creating To Do List Program - Question

2013-09-29 Thread Dominik George
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA512



Rafael Knuth  schrieb:
>Hej there,
>
>I am writing a to do list program in Python 3.0.
>
>Earlier this week, I shared my first iteration on the mailing list,
>and the feedback was that I should learn how to create, write to and
>read from a text file – which I did. Below please find my second
>iteration. I know my program is super cheesy & primitive, but I don’t
>care, it does what I expect it to do, and I will improve it in further
>iteration cycles. As of now, I want to understand how I can add
>further functionalities to my program such as: appending items to the
>list, removing and replacing items. Can anyone help? Thank you very
>much in advance!
>
>print("""
>
>Welcome World's Most Geeky To Do List Program
>
>G E E K L I S T  1 . 0
>
>If you want to add items to the list, enter:
>
>text_file = open("ToDoList.txt", "w")
>text_file.write("add your item here ")
>text_file.write("add action item here ")
>text_file.write("you get the point, right?")
>text_file.close()
>
>If you want to print your to do list, enter:
>
>text_file = open("ToDoList.txt", "r")
>print(text_file.read())
>text_file.close()
>
>We are constantly improving our program, watch out for version 2.0!
>
>""")
>___
>Tutor maillist  -  Tutor@python.org
>To unsubscribe or change subscription options:
>https://mail.python.org/mailman/listinfo/tutor

Hi,

why don't you remove the first and last line and then use the "cat" interpreter 
instead?

Seriously, you should try to write a program first, then ask for help. Just 
follow the instructions from your output below!

- -nik
- --
Diese Nachricht wurde von meinem Android-Mobiltelefon mit K-9 Mail gesendet.
-BEGIN PGP SIGNATURE-
Version: APG v1.0.8-fdroid

iQFNBAEBCgA3BQJSSJU/MBxEb21pbmlrIEdlb3JnZSAobW9iaWxlIGtleSkgPG5p
a0BuYXR1cmFsbmV0LmRlPgAKCRAvLbGk0zMOJT1IB/9l3mmERfFT7zzQo1HLharf
j/bNkwpouG4rJ6dB+/4RIu9EBvUl0i3uvA9O0Lwo4B6cU4ulHLyZd/dj1vdYs4a/
7XfUIlb78fIhHWgpgfjglXheQeUaruspfc/XfYZ0MJSwWVoAyC9C/dtOGGq3nlfM
K6eE0ScoteVRsW5UsqIv5qzbEqjWGW/j8frySj7uYEr24VP/SVKT2MwAZy1zv7uy
8FwrmvGjyx8lXa/sEVfZzpNXgikENQumt6ZCUMcNf2FM/0kxzie3e8Z7V/Ofkygt
ccWMoMRlmcF/l1m45bPbQ6RFw4frTOekCujNHNa5RR+OEi3HcugKMzMKDGqBn5M8
=/cCh
-END PGP SIGNATURE-

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


Re: [Tutor] Creating To Do List Program - Questions

2013-09-30 Thread Dominik George
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA512



Rafael Knuth  schrieb:
>Hej there,
>
>apologies if you're receiving my mail for a second time, I had some
>issues with Google and I just want to make sure you will receive my
>email.
>
>I am writing a to do list program in Python 3.0.
>
>Last week, I shared my first iteration on the mailing list, and the
>feedback was that I should learn how to create, write to and read from
>a text file – which I did. Below please find my second iteration. I
>know my program is super cheesy & primitive, but I don’t care, it does
>what I expect it to do, and I will improve it in further iteration
>cycles. As of now, I want to understand how I can add further
>functionalities to my program such as: appending items to the list,
>removing and replacing items. Can anyone help? Thank you very much in
>advance!
>
>print("""
>
>Welcome World's Most Geeky To Do List Program
>
>G E E K L I S T  1 . 0
>
>If you want to add items to the list, enter:
>
>text_file = open("ToDoList.txt", "w")
>text_file.write("add your item here ")
>text_file.write("add action item here ")
>text_file.write("you get the point, right?")
>text_file.close()
>
>If you want to print your to do list, enter:
>
>text_file = open("ToDoList.txt", "r")
>print(text_file.read())
>text_file.close()
>
>We are constantly improving our program, watch out for version 2.0!
>
>""")
>___
>Tutor maillist  -  Tutor@python.org
>To unsubscribe or change subscription options:
>https://mail.python.org/mailman/listinfo/tutor

Plonk!
- --
Diese Nachricht wurde von meinem Android-Mobiltelefon mit K-9 Mail gesendet.
-BEGIN PGP SIGNATURE-
Version: APG v1.0.8-fdroid

iQFNBAEBCgA3BQJSSVAiMBxEb21pbmlrIEdlb3JnZSAobW9iaWxlIGtleSkgPG5p
a0BuYXR1cmFsbmV0LmRlPgAKCRAvLbGk0zMOJRHPCACXtUPhURIgmZJYJ9dN/3aO
NsLmHWS3aQK3DBHI9Yjle8VFDjjPEE4mVEB/qsEJRddu4SbmiwPzy7P961X13aOg
SSX/jvTj+CfrapxgslCgtTF3K3i65XHJ5CL8CE2TWBhaxM2ZET+q66owAYKfQBGH
CoAVX4SwKHKCeFU5I40ft09kPh6LAwxogF3whVi6eYwdlDSGxsYABdqhegnR6JL+
tW6vNZiTkDa4vihmsQ5md/2Lw0c5fG+3wEXFAcwl9+Cu39cHD2btQDmSPuPo730h
z4b1fa7noaNbOnuhapwEQt81kSEayzbfugy5rL3deBmQUSmrFNQc0/NxdD2+k9Ea
=AYpY
-END PGP SIGNATURE-

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


Re: [Tutor] Creating To Do List Program - Question

2013-09-30 Thread Dominik George
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA512



Rafael Knuth  schrieb:
>Hej there,
>
>@Alan @Joel:
>I didn't know that pouring corn on newbies is the purpose of a tutor
>mailing list.
>Why don't you try writing a program instead? Why don't you use the cat
>interpreter instead?
>I tried my best and that's what I came up with, and I am eager to
>learn form experienced programmers - step by step at my own pace and
>in my own manner. Hence, I find your responses arrogant,
>self-righteous and discouraging.
>
>I do not understand why you don't consider what I wrote not a program
>("Hello World!" in a more elaborate form), as the user is actually
>able to a list, to write to and reads from it (in a very primitive
>manner though).  Can anyone explain? However, I find that hint to
>learn to use SQLite - thank you for that.
>
>All the best,
>
>Rafael
>
>Rafael
>
>
>
>
>On Mon, Sep 30, 2013 at 1:43 AM, Alan Gauld 
>wrote:
>> On 29/09/13 21:42, Rafael Knuth wrote:
>>
>>> iteration. I know my program is super cheesy & primitive, but I
>don’t
>>> care, it does what I expect it to do,
>>
>>
>> Really? You wrote a program that printed out a different
>> program to the one you ran and that's what you wanted?
>> It doesn't do anything about creating a ToDo list.
>> It doesn't even bring you any closer to creating a ToDo list.
>>
>> Now, if instead of just printing it you actually ran
>> the code you print it might actually get you somewhere
>> closer.
>>
>> But at the moment your program is exactly equivalent to
>>
>> print('Hello world')
>>
>> except more verbose in its message.
>>
>>
>>> print("""
>>>
>>> Welcome World's Most Geeky To Do List Program
>>>
>>> G E E K L I S T  1 . 0
>>>
>>> If you want to add items to the list, enter:
>>>
>>> text_file = open("ToDoList.txt", "w")
>>> text_file.write("add your item here ")
>>> text_file.write("add action item here ")
>>> text_file.write("you get the point, right?")
>>> text_file.close()
>>>
>>> If you want to print your to do list, enter:
>>>
>>> text_file = open("ToDoList.txt", "r")
>>> print(text_file.read())
>>> text_file.close()
>>>
>>> We are constantly improving our program, watch out for version 2.0!
>>>
>>> """)
>>
>>
>> --
>> 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
>___
>Tutor maillist  -  Tutor@python.org
>To unsubscribe or change subscription options:
>https://mail.python.org/mailman/listinfo/tutor

Hi Rafael,

it's not your program - it's your attitude. We expect you to learn for yourself 
as well, and putting the commands you output into a script and execute it 
clearly isn't beyond what we can expect from someone who can use a mail program.

This attitude even shows in your last mail - you accuse Alan and Joel, then 
quote *my* bad behaviour, blaming them for it.

You are welcome here, but please always make at least an educated guess about 
your problem.

- -nik
- --
Diese Nachricht wurde von meinem Android-Mobiltelefon mit K-9 Mail gesendet.
-BEGIN PGP SIGNATURE-
Version: APG v1.0.8-fdroid

iQFNBAEBCgA3BQJSSV3rMBxEb21pbmlrIEdlb3JnZSAobW9iaWxlIGtleSkgPG5p
a0BuYXR1cmFsbmV0LmRlPgAKCRAvLbGk0zMOJe3UB/0UDtC1HbqL8XCTAfkuXb00
07BL9H7W/lkk8wPR8Wiq4TLjnW9lVoFn3Y68Pebity/J/MDLj10u2MgV11HV5it8
Sb/XLDSAs4fKnJaHbDUsyaAJ2aBbygUT2T4OI8sFKURikPBmgItX36H68dGF8V97
BkeFrMDzqbuzubClhfNjh9jeqsvf3Lfzy4hx6M1SXoKAHg6uv3nu+pPme0n5Phzt
iUjkQR8mD86KPE4kcN0qCCpAfxJVuqHWq9ZCtxpEVYwHKo1GbGaRwBPbr6/aDJ4m
IF1mwI7pOKdNNftA4+szAGUbMEKCmaPIaBTdf34rtrTj7XLTH0/Kyop4lz/fg26h
=Q+KX
-END PGP SIGNATURE-

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


Re: [Tutor] Creating To Do List Program - Question

2013-09-30 Thread Dominik George
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA512



Rafael Knuth  schrieb:
>Dominik,
>
>> it's not your program - it's your attitude. We expect you to learn
>for yourself as well, and putting the commands you output into a script
>and execute it clearly isn't beyond what we can expect from someone who
>can use a mail program.
>
>Thanks for the clarification, you were the third kid on the block I
>missed to add to my feedback on behavior I find inappropriate.
>You are suggesting that my attitude is wrong, but what's wrong about
>doing baby-steps even if it's at the level of someone barely able to
>use a mail program? I simply want to create a To Do List program, and
>I couldn't find any tutorials on that, therefore I reached out to the
>mailing list. And here I am, justifying myself for my first clumsy
>attempt to accomplish my goal.
>
>I am still hoping that I will get some feedback from anyone on that
>list that will help me make a tiny little next step.
>
>Thank you in advance,
>
>Rafael

You already got that - remove the surrounding print() and put it in a script.

Why haven't you taken that advice yet?

- -nik
- --
Diese Nachricht wurde von meinem Android-Mobiltelefon mit K-9 Mail gesendet.
-BEGIN PGP SIGNATURE-
Version: APG v1.0.8-fdroid

iQFNBAEBCgA3BQJSSWN7MBxEb21pbmlrIEdlb3JnZSAobW9iaWxlIGtleSkgPG5p
a0BuYXR1cmFsbmV0LmRlPgAKCRAvLbGk0zMOJZPLCACyAJ1DL33nvDOZVj3/heWG
zciLXGnvoINbiufZLjl5yPn/yxzJdS2knwUbE1AhuzoxiZCoLFMzZKN4BnXWdG1A
cjqj8e/cin2YUWBG1eu53wcdU4iAhbwaKzLgP5soy8ZLc2cnWtf5Dmrgc+IGw02f
/LZPBgw+XjngbYQ1U8RMH/15NKYuMVhy9WzRO19I4sOUCrQQspEBhvRwejS4eApO
l7PwaHI3A6pxdWITaX/C8nVOpicUMVEDx9LE8+hswvGO6yIulyCkelkeAJgTcj5s
MN6QDglZaguWLcDH3gGXfN6Go28RLPiC2hD1+Hv+JbCriVWxZd2WIBzh5K3It/OT
=0kOH
-END PGP SIGNATURE-

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


Re: [Tutor] Creating To Do List Program - Question

2013-09-30 Thread Dominik George
Hi Rafael,

> > Your original program had some code that interacted with the user.  So
> > when you went from that to a giant print statement, I, and proably many
> > others, thought you were just kidding.
> 
> I noticed that, but I was serious about that. I mean, my giant print
> statement was really ridiculous to say the least but it did what I
> wanted the program to do - adding items to the To Do List and printing
> that list. However, I knew this was my very first iteration and I
> wanted to improve my program by making those incremental baby steps.

That still doesn't explain why you only have a print() statement print
Python statements, rather than execute these Python statements.

> > Are you using Python 3.3, under Windows?
> 
> Python 3.0 under Windows.

Why, exactly?

> > Can you write code in a function, have it take parameters and return
> > results?  Do you know how to call such a function?
> 
> Yes.

Then do it, I'd suggest.

> > Do you know what a file is?  Do you know the difference between text
> > file and binary file?  Can you read a text file into a list?  Can you
> > write a list of strings out to a text file?
> 
> I worked with text files yet, I have to admit I haven't worked with
> binary files though - and I don't know yet what they are.  But I will
> figure that out.

That's basically any file that contains, or is supposed to contain,
non-printable characters, or where \n has another meaning than
liebreaking. You normally read a plaintext file line by line and a
binary file byte by byte.

> > If you understand all these pieces, you're probably ready to try to
> > construct a todo list program.  If not, I second the suggestion to
> > follow a tutorial, till it's covered at least all of these.
> 
> Ok, cool.

OTOH, *if* your claim that you understand the concepts mentioned by Dave
isn't an ill-minded overestimation, I wonder why you don't go and use
these skills. Doyou lack a concept of how to logically build up your
code, or what's the main issue?

> Ok, so I will rewrite that To Do list as you (and the others)
> suggested and I will get back to you in case I have any further
> questons.

That's good ☺!

> > Once you think you have the function written, write a simple top-level
> > program that calls the function and prints the results.  Then have it
> > print the results one line at a time.
> 
> I don't understand yet what a top-level program is, but I will figure that 
> out.

The thing the python interpreter calls, that is not in a class:, def: or
some other block.

> Again, thank you all.
> I have a fairly good understanding of how I should proceed now.

You're welcome back with your results ☺!

-nik

-- 
 Ein Jabber-Account, sie alle zu finden; ins Dunkel zu treiben
und ewig zu binden; im NaturalNet, wo die Schatten droh'n ;)!

PGP-Fingerprint: 3C9D 54A4 7575 C026 FB17  FD26 B79A 3C16 A0C4 F296


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


Re: [Tutor] sqlite3 COMMIT directive

2013-09-30 Thread Dominik George
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA512

Hi,

>sqlite3.OperationalError: cannot commit - no transaction is active

That means that you have to execute "BEGIN TRANSACTION" before using atomic 
commits.

http://www.sqlite.org/lang_transaction.html
http://sqlite.org/transactional.html

>I've been reading about the COMMIT directive but apart from its
>relationship with ROLLBACK, I haven't been able to figure out how it is
>
>relevant to my problem here.

It isn't. What is relevant is whether you use transactions or not.

- -nik
-BEGIN PGP SIGNATURE-
Version: APG v1.0.8-fdroid

iQFNBAEBCgA3BQJSSl6rMBxEb21pbmlrIEdlb3JnZSAobW9iaWxlIGtleSkgPG5p
a0BuYXR1cmFsbmV0LmRlPgAKCRAvLbGk0zMOJSUPB/9bNtMNiXOf+k8mrVRr6+NC
XBVMcSrXHIKbdojYthPNF7kT5DjVoEzvHPIwL01b+V7metjTA58FUGbE2CHP+0Ho
Ydr60MlXt5VhqOYLHy7KF3nZ6mkutcLGhSJzncdhYeYZG9QSk3W1Z7/eyPLs3Pzk
77Y6NjF/b7R47ey4dXfalJbkE2TGyVVixPzVaLutXIIPqXQdLracqlPa/jen0esK
j210UjCkMY/stlqEG0ADLX0PlNvyVYxuB/t70mRegj8GqX4txtOMDlJaasNJavkT
J2niBAw3ftW04qpJjJgnvdxTnw0YgW7+rqhm6/1gvLsPopnKStYp3NAFvXuidI1U
=L3tk
-END PGP SIGNATURE-

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


Re: [Tutor] Help please

2013-10-17 Thread Dominik George
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA512

Todd Matsumoto  schrieb:
>> #1. Error handling for the files to ensure reading only .txt file
>Look up exceptions.
>Find out what the string method endswith() does.

One should note that the OP probably meant files of the type text/plain rather 
than .txt files. File name extensions are a convenience to identify a file on 
first glance, but they tell absolutely nothing about the contents.

So, look up MIME types as well ;)!

- -nik
-BEGIN PGP SIGNATURE-
Version: APG v1.0.8-fdroid

iQFNBAEBCgA3BQJSX/F3MBxEb21pbmlrIEdlb3JnZSAobW9iaWxlIGtleSkgPG5p
a0BuYXR1cmFsbmV0LmRlPgAKCRAvLbGk0zMOJZxHB/9TGh6F1vRzgZmSMHt48arc
jruTRfvOK9TZ5MWm6L2ZpxqKr3zBP7KSf1ZWSeXIovat9LetETkEwZ9bzHBuN8Ve
m8YsOVX3zR6VWqGkRYYer3MbWo9DCONlJUKGMs/qjB180yxxhQ12Iw9WAHqam1Ti
n0CCWsf4l5B3WBe+t2aTOlQNmo//6RuBK1LfCrnYX0XV2Catv1075am0KaTvbxfB
rfHHnR4tdIYmZ8P/SkO3t+9JzJU9e+H2W90++K9EkMTBJxUhsa4AuZIEr8WqEfSe
EheQMUp23tlMgKRp6UHiRJBljEsQJ0XFuYa+zj6hXCXoru/9ReHTRWcvJEpfXxEC
=hJ0m
-END PGP SIGNATURE-

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


Re: [Tutor] Passing arguments?

2013-10-20 Thread Dominik George
Hi,

> I've written the code below the assignment, and I think I have everything
> covered in terms of asking the user for the information I need and somehow
> calculating costs, but I'm just ridiculously confused on the order and
> placement of the functions and components of this program- specifically the
> shiprate variable. Thank you in advance for any help.

so, you are confused. Cool ☺! But, what is your question ;)? Your
subject suggests it has something to do with passing arguments to a
script, but, umm… I do not see what this has to do with the rest of your
mail ;).

Also, please reformat your code in a readable manner, i.e. remove the
many empty lines, reformat function calls according to style guide, etc.

Cheers,
Nik

-- 
 Auf welchem Server liegt das denn jetzt…?
 Wenn es nicht übers Netz kommt bei Hetzner, wenn es nicht
gelesen wird bei STRATO, wenn es klappt bei manitu.

PGP-Fingerprint: 3C9D 54A4 7575 C026 FB17  FD26 B79A 3C16 A0C4 F296


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


Re: [Tutor] Auto-response for your message to the "Tutor" mailing list

2013-10-20 Thread Dominik George
> Your message for tutor@python.org, the Python programming tutor list,
> has been received and is being delivered.  This automated response is
> sent to those of you new to the Tutor list, to point out a few
> resources that can help with answering your own questions, or improve
> the chances of getting a useful answer from the other subscribers.

Thank you, but…

…I have been a member of the list for many weeks now and have posted
quite a few messages. Is there a reason I am receiving this friendly
greeter more than once?

-nik

-- 
# apt-assassinate --help
Usage: apt-assassinate [upstream|maintainer] 

PGP-Fingerprint: 3C9D 54A4 7575 C026 FB17  FD26 B79A 3C16 A0C4 F296


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


Re: [Tutor] basic function concept

2013-11-16 Thread Dominik George
> main()
> 
> Can someone tell me why main is not being given any arguments?

Because you didn't write any there.

-nik

-- 
Wer den Grünkohl nicht ehrt, ist der Mettwurst nicht wert!

PGP-Fingerprint: 3C9D 54A4 7575 C026 FB17  FD26 B79A 3C16 A0C4 F296


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


Re: [Tutor] Class attribute error

2013-11-16 Thread Dominik George
On Sat, Nov 16, 2013 at 09:13:13AM -0800, reutest wrote:
> class myclass():
>   
> def test(self):
>   print "print this line"
>   
> 
> if __name__ == '__main__':
>   myclass.run()

Is that a question?

If I were to guess, I'd say you should have asked "Why does this say
that myclass does not havea run method?". Then the simple answer is:
Because, well, it doesn't! Why do you expect it to have one?

-nik

-- 
Wer den Grünkohl nicht ehrt, ist der Mettwurst nicht wert!

PGP-Fingerprint: 3C9D 54A4 7575 C026 FB17  FD26 B79A 3C16 A0C4 F296


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


[Tutor] Sending sensible e-mail (was: Re: (no subject))

2013-11-22 Thread Dominik George
Hi,

> Subject: [Tutor] (no subject)

On a side note, please learn how to send e-mail.

Thanks,
Nik

-- 
* mirabilos is handling my post-1990 smartphone *
 Aaah, it vibrates! Wherefore art thou, demonic device??

PGP-Fingerprint: 3C9D 54A4 7575 C026 FB17  FD26 B79A 3C16 A0C4 F296


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


Re: [Tutor] Fibonacci Series

2013-11-24 Thread Dominik George
Hi,

> a, b = b, a +b

> a = b = 1
> b = a + b = 1 + 1 = 2

Your issue is that you interpret the assignment wrong. You seem to think
that it assigns b to a and THEN a+b to b, which is not the case. The
right side of the assignment creates a tuple, and the left side unpacks
it. It is the same as:

t = (b, a+b)
a = t[0]
b = t[1]

You see that a has not been assigned yet when the second part is calculated.

Cheers,
Nik

-- 
* mirabilos is handling my post-1990 smartphone *
 Aaah, it vibrates! Wherefore art thou, demonic device??

PGP-Fingerprint: 3C9D 54A4 7575 C026 FB17  FD26 B79A 3C16 A0C4 F296


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


Re: [Tutor] Else vs. Continue

2013-11-24 Thread Dominik George
Hi,

> I stumbled upon the "continue" statement and to me it looks like it
> does exactly the same as else. I tested both else and continue in a
> little program and I don't see any differences between both. Is my
> assumption correct or wrong? If the latter is the case: Can you give
> me examples of continue usage that couldn't be done with else?

In general, you can translate quite many code samples into different
ones.

The difference is that else is used in an if control block, and continue
is used only in loops and does exactly one thing: Skip the rest of the
loop body, and begin the next iteration.

Of course, you could do a lot of tests in the loop and use a lot of
else: pass blocks that, after hitting a point where you want to escape
the loop, skip the rest of the effective code, but that's cumbersome.

If you want to exit a loop at a certain point, just use continue (or
break to skip all remaining operations).

To add to your confusion: while loops do have an else part in Python:

while CONDITION:
... do something ...
else:
... do something else ...

The else part is executed exactly in the case that CONDITION is no
longer True - but *not* when you break from the loop before that.

-nik

-- 
* concerning Mozilla code leaking assertion failures to tty without D-BUS *
 That means, D-BUS is a tool that makes software look better
than it actually is.

PGP-Fingerprint: 3C9D 54A4 7575 C026 FB17  FD26 B79A 3C16 A0C4 F296


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


Re: [Tutor] Usefulness of classes and necessity of inheriting classes

2013-11-25 Thread Dominik George
Hi Reuben,

> Question no 1:
> --
> I would like to know why do we actually inherit classes? What would be the
> benefit of inheriting?

I think this is not the classical explanation of this, but when teaching
programming to my students, I make a very great deal of the following:

All things programming (even all things to do with computers) are about
agreements (dt. Abmachungen) and promises (dt. Versprechen). Protocols
are agreements about the communication between programs (or devices),
and a programming language is an agreement about communication between a
programmer and the machine. A program, or an interface, then, is an
agreement between the user and the programmer and his machine.

The important thing is that, as is to be expected from the kids I teach
towards their teachers, friends and family, if the agreement is
fulfilled by both sides, everything will work out well.

The machine gives us a promies: if we feed it with certain binary
operations, it will do a certain thing, and exactly this one thing
(unless it has a bug).

The Python interpreter, or its developers, gives us a promise: if we
feed it with certain lines/blocks of code, it will do exactly as asked.
If it doesn't, most likely we broke the agreement in some way or another
(unless the interpreter or the machine udner it has a bug).

Now, you could see a class as a promies to both the interpreter and
users of your class (if you use it in a library): A certain class has
certain attributes and methods, and this is a promise.

It follows, that if a class inherits from another class, then this class
will keep the promise made by the base class as well - it will (at
least) have the interface the base class is known to have.

Obviously, a developer could break this promise by manipulating stuff in
the inheriting class in an unexpected way, but that's not our fault then
nor is it Python's or the machine's fault ;).

Now, normally, you extend a class (inherit from it) when you want your
own class to basically behave the same way the base class does, and
expose more or less the same interface. Maybe you even do not want to
change the internal behaviour, but only add a tiny thing.

My experience in classroom teaching has shown that thinking of
programming and CS as making keeping promises helps a lot.

> If possible, a practical example would be of great help

A practical example, as in code - an example that has a practical use is
hard to give. But I'll try anyway:

  class Display():
   This class can put pixels on a monochrome display """

  def __init__(self):
  """ Do setup stuff for the display """
  pass

  def put(self, pos):
  """ Puts a pixel at an (x, y) pos
  pass

  def clear(self, pos):
  """ Clears a pixel at an (x, y) pos """
  pass

  class ColorDisplay(Display):
  """ This class behaves just like the Display class,
  but can control colour. """

  # The setup stuff is copied/inherited from the base

  def put(self, pos, colour=None):
  """ This method overrides the base method, but calls it
  in case the user does not use colour, so our interface
  is universal """

  if not colour:
  return Display.put(self, pos)

  # do colourful magic stuff here


You see that both classes can be used in exactly the same manner, but
the second one has been extended by an optional colour attribute in the
put method.

From this example, you can conclude that the inheritance was chosen to
avoid code duplication, and to sign the promise that the interfaces are
somewhat compatible.

> Question no 2:
> --
> 
> Why would I ever use a class? I understand this is strange question
> 
> May be an example to make me understand would be useful.
> 
> Or may be answering the question should be rephrased as "Why not use
> modules instead of classes?"

Because you cannot (well you can, but not without turning right into a
zombie) make a copy of a module. When you instantiate a class, you get a
copy of its attributes in something like a dictionary (exposed in a
different way) and it is independent of the other copies.

The only reasonable thing you do with a module is importing it. With
that, you get a copy of its *name* - mind you, modules and importing are
all about names and namespaces, no more no less.

So imagine a module named spam, with these contents:

  bacon = 5
  eggs  = 7

Now, do something like this:

  import spam as spam1
  import spam as spam2

This is completely valid, but you only get two names pointing to the
exact same thing:

  spam1.bacon = 10
  print(spam2.bacon)

This will give 10. You most likely did not want that ;).

What you *can* do is write simple functions in a module that expect a
certain (promised) data structure as input and manipulates it in a
(promised) way, like so:

  def grow_a_human(human):
  human['length'] += 10

  my_human = {'le

Re: [Tutor] How to set variables inside a class()

2013-11-26 Thread Dominik George
Hi Reuben,

> class Animal():
> 
>   flag = True
>   print flag

Are you sure you know what this does ;)? Normally, you initialize all
variables in the constructor.

>  test.flag = False

> 1)Inside the Animal class(), How can I set the variable 'flag' to FALSE?

Your qustion is a bit unclear. In your above code, you showed at least
two ways of achieving that - one would be in the place where you have
flag = True in your class definition, and the second is when you do
test.flag = False on the instance.

But remember that classes are schemes; what really counts are the copies
of them called instances.

So I think your question is: "When calling a method in an instance of my
class, how do I make it set the attribute flag to False?"

The simple answer is: In the same way you set the name in the
constructor - self.flag = False .

I suggest you should pay more attention to the repeating patterns you
find when programming Python. I have observed that the answer to your
question was all in your code sample ;). So while I (and others) will
happily help you anyway, in order to improve your learning efforts,
please do the following next time you ask:

 - Look at the code you have
 - Try to find a pattern that looks similar to what you want to achieve
 - Try it ;)
 - If it fails or is unclear, report that, your assumptions and the results
   so we can clarify it
 - If you do not find such a pattern, go ahead and just ask, but give a
   statement of what you looked out for :).

Cheers,
Nik

-- 
 Ein Jabber-Account, sie alle zu finden; ins Dunkel zu treiben
und ewig zu binden; im NaturalNet, wo die Schatten droh'n ;)!

PGP-Fingerprint: 3C9D 54A4 7575 C026 FB17  FD26 B79A 3C16 A0C4 F296


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


Re: [Tutor] How to set variables inside a class()

2013-11-26 Thread Dominik George
Hi,

> By setting test.flag you are creating a new instance level attribute
> that exists only within the test instance. That's legal Python
> but usually its not a good idea to have different instances of
> the same class having different attributes.

maybe this becomes clearer by breaking down the whole thing to something
more basic: dictionaries.

As I mentioned before, classes and their instances are more or less
dictionaries containing their attributes.

When you set a variable at class scope (like your flag in the class
definition), then this is added to the dictionary of the class.

Now when zou instantiate the class, then the dictionary is copied to the
instance (carying references to the same data inside it, mind you!), so
the instance has an attribute called flag available, pointing to the
same data as the flag in the class.

You can do things such as:

   my_instance.f = False

or

   self.f = False

This will then assign the *new* data to the named attribute in the
instance, thus releasing that reference to the class' attribute data.

And that's all of the magic - shallow copies of a dictionary that you
sometimes overwrite. There's not much more to static attributes in
Python.

You can prove this by manipulating the copy of a class attribute in an
isntance without replacing it, like so:

   class C():
   entries = []

   c = C()
   c.entries.append('foo')

   c.entries
   C.entries

You will find that both the last lines return the same thing - the list
with 'foo' appended, because you just manipulated the same list object
in place.

One last thing, when you create an instance-level attribute, you do that
inside a method by adding it to the self reference. This only adds it to
the dictionary of that instance - normally, you setup all attributes in
the constructor because that guarantees that they are set for all new
instances.

You could as well use class-level attributes to initialize attributes
for all instances, but as noted above, you must pay very close attention
then because if you happen to manipulate such an attribute in place in
one class before replacing it, you manipulate it for all other
isntances, too.

-nik

-- 
Wer den Grünkohl nicht ehrt, ist der Mettwurst nicht wert!

PGP-Fingerprint: 3C9D 54A4 7575 C026 FB17  FD26 B79A 3C16 A0C4 F296


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


Re: [Tutor] Dict

2013-11-26 Thread Dominik George
Hi,

> Is it possible to sort dict & to get result as dict?
> if it is possible, please give some example.

By what do you want to sort it? By key? By value? By a combination of
both?

Cheers,
Nik

-- 
 Ein Jabber-Account, sie alle zu finden; ins Dunkel zu treiben
und ewig zu binden; im NaturalNet, wo die Schatten droh'n ;)!

PGP-Fingerprint: 3C9D 54A4 7575 C026 FB17  FD26 B79A 3C16 A0C4 F296


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


Re: [Tutor] Splitting lists with strings and integers

2013-11-26 Thread Dominik George
Hi,

> I have a list with mixed strings/integers.  I want to convert this to a
> list of lists, and I want the numbers to get stored as integers.

First, let's do it with a list comprehension. You should really learn those if 
you do serious Python programming ;)!

   list2 = [[int(z) if z.isdigit() else z for z in y] for y in [x.split(" ") 
for x in list1]]

Now, to convert every possible numeric string in a list to int in a more
readable fashion:

   for x in xrange(len(animal)):
   if animal[x].isdigit():
   animal[x] = int(animal[x])

So:

 - the isdigit() method of a string tells you if it is numeric
 - int() casts to an integer

The list comprehension does the whole converion with list
comprehensions. You should consider readability when doing such things,
but you should learn it.

-nik   

-- 
# apt-assassinate --help
Usage: apt-assassinate [upstream|maintainer] 

PGP-Fingerprint: 3C9D 54A4 7575 C026 FB17  FD26 B79A 3C16 A0C4 F296


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


Re: [Tutor] Splitting lists with strings and integers

2013-11-26 Thread Dominik George
> >for x in xrange(len(animal)):
> >if animal[x].isdigit():
> >animal[x] = int(animal[x])
> >
> 
> Before posting anything else would you please do a tutorial
> yourself. The above for loop is appalling newbie code, I'll leave
> you to post the Pythonic format.

Can I trust my ears? Did you just make a move to expell me from posting
newbie-readable code on a newbie-list :D?

Believe me, I do not need a tutorial. Seriously not. Just in case you
missed it, the pythonic code is a few lines above in my post.

If that is not enough for you, start a private Python helpdesk with all
your glory and remove me from the list.

And in the future, please refrain from carpeting me on a public mailing
list.

Thanks!

-- 
Wer den Grünkohl nicht ehrt, ist der Mettwurst nicht wert!

PGP-Fingerprint: 3C9D 54A4 7575 C026 FB17  FD26 B79A 3C16 A0C4 F296


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


Re: [Tutor] Splitting lists with strings and integers

2013-11-27 Thread Dominik George
Mark Lawrence  schrieb:
>Dominik,
>
>I'm very sorry about the above, I really should know better than to
>post 
>at stupid o'clock in the morning when I'm already exhausted.

Thanks, Mark :)!

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


Re: [Tutor] Allocation of serial ports

2013-11-29 Thread Dominik George
Hi,

>So, how can I ensure that port A is always ttyUSB0

http://hintshop.ludvig.co.nz/show/persistent-names-usb-serial-devices/

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


Re: [Tutor] TypeError: range() integer end argument expected, got float.

2013-11-29 Thread Dominik George
Hi,

> Using python 7.3

I think we must update 'import antigravity' to say something about
python-driven flux capacitors :þ ...

> def PaymentTable(balance, annualInterestRate, payment):

You should not CamelCase function names.

> upperbound = round((balance + (monthlyinterest * 12)) / 12, 0)

Your error is because round() does not cast to int. It produces an
integer number in a strict mathematical sense, but not as a data type.

Use int() for that.

> for payment in range(lowerbound, upperbound, 10):
> if PaymentTable(balance, annualInterestRate, payment) == True:  Error 
> occurs at this line
> print 'Lowest Payment: ', payment
> break

A few notes about that.

1. You mentioned above that you use Python 7.3. As already said, I do
not know what that is, because right now there is Python 2.x and 3.x. I
assumed you meant 3.3, because that is widely used, but in that case,
your print statement would not work. print() is a function, please get
used to that.

2. Do not compare with True. Either the expression is True, or it is
False. No need to be redundantly explicit ;).

3. There might be a more pythonic way to find the lowest payment. List
comprehensions and min() come to mind; however, due to your naming
conventions I do not fully understand what the code is supposed to find.
Something called PaymentTable is supposed to return a table-like thing,
not a boolean. Maybe you should get a bit more into detail about that
(comment your code, for example ;)) and help us give you more hints on
it.

Cheers,
Nik

-- 
* mirabilos is handling my post-1990 smartphone *
 Aaah, it vibrates! Wherefore art thou, demonic device??

PGP-Fingerprint: 3C9D 54A4 7575 C026 FB17  FD26 B79A 3C16 A0C4 F296


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


Re: [Tutor] Loop over floating point values

2013-12-01 Thread Dominik George
Hi,

> - Do not create a list of the floating point values as i=[0.01, 0.02,
> 0.03..] - either like that or by using a suitable mathematical formula
> combined with a list comprehension

You could simply write your own version of xrange that does it, as a
generator:

  def xrange_f(start, stop, step):
  x = start
  while x < stop:
  yield x
  x += step

Then, in your code, you can do:

  for f in xrange_f(0, 10, 0.01):
  pass

-nik

-- 
* concerning Mozilla code leaking assertion failures to tty without D-BUS *
 That means, D-BUS is a tool that makes software look better
than it actually is.

PGP-Fingerprint: 3C9D 54A4 7575 C026 FB17  FD26 B79A 3C16 A0C4 F296


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


Re: [Tutor] how to edit program files in Python?

2013-12-19 Thread Dominik George
Hi,

> My son and I just opened "Python for Kids" and we're working our way
> through the lessons.  Sometimes he mistypes the lines and hits return
> and discovers after that that he made a mistake in the line.  But,
> when we try to correct the line, we are not able to.  We just get that
> loud beepy sound telling us it's not possible.

That's because you are using some interpreter (or wrapper) that is not
suited for the job (maybe not suited for anything, really ;)). I guess
this thing might be IDLE. I am not going into detail about why I do not
see IDLE fit for learning Python ...

> So... is there any way to go back up to the previous line and correct
> the syntax?  As it is now we are starting the entire file over.  It's
> really cumbersome.  Is it supposed to be this way?

... and I won't go into detail about why I do not see the book you are
... reading fit for learning Python ;).

To get to the core of your question: Just choose your favourite text
editor, write the code in a text file, save it as .py and
then execute that script.

Cheers,
Nik

-- 
* concerning Mozilla code leaking assertion failures to tty without D-BUS *
 That means, D-BUS is a tool that makes software look better
than it actually is.

PGP-Fingerprint: 3C9D 54A4 7575 C026 FB17  FD26 B79A 3C16 A0C4 F296


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


Re: [Tutor] class variables

2013-12-20 Thread Dominik George
Hi,

> I am a little confused about class variables: I feel like I've repeatedly
> seen statements like this:

please take a look at the archives - this topic has been discussed on
this list recently.

-nik

-- 
* mirabilos is handling my post-1990 smartphone *
 Aaah, it vibrates! Wherefore art thou, demonic device??

PGP-Fingerprint: 3C9D 54A4 7575 C026 FB17  FD26 B79A 3C16 A0C4 F296


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


Re: [Tutor] The Charms of Gmail

2013-12-21 Thread Dominik George
> I'm sorry Mark, I'm stuck with using gmail [...]

Use sane e-mail, then.

-- 
# apt-assassinate --help
Usage: apt-assassinate [upstream|maintainer] 

PGP-Fingerprint: 3C9D 54A4 7575 C026 FB17  FD26 B79A 3C16 A0C4 F296


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


Re: [Tutor] The Charms of Gmail

2013-12-22 Thread Dominik George
> I'm no expert, but would a (semi-)decent email client help?

Probably not, as Google's IMAP implementation is hopelessly broken
beyond all repair.

-nik

-- 
* concerning Mozilla code leaking assertion failures to tty without D-BUS *
 That means, D-BUS is a tool that makes software look better
than it actually is.

PGP-Fingerprint: 3C9D 54A4 7575 C026 FB17  FD26 B79A 3C16 A0C4 F296


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


Re: [Tutor] The Charms of Gmail

2013-12-22 Thread Dominik George
> >OMG, so obvious. I actually had to reply to several messages in recent
> >digests, and I utterly resented my clunky technique the second I saw
> >you'd mentioned this. Thanks.
> >
> >--
> >Keith
> >
> 
> This might also prevent you from completely losing all threading.
> This has happened on at least the last six messages I've seen from
> you.

And it is what I hate *most*, especially on mailing lists. It makes me
want to call for a complete GMail ban, because it appears GMail users
*always* manage to do such things ...

Please, don't get me wrong, but by all means get a *complete* sane mail
setup (including layer 8!).

-nik

-- 
 Ein Jabber-Account, sie alle zu finden; ins Dunkel zu treiben
und ewig zu binden; im NaturalNet, wo die Schatten droh'n ;)!

PGP-Fingerprint: 3C9D 54A4 7575 C026 FB17  FD26 B79A 3C16 A0C4 F296


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


Re: [Tutor] what's your name? (to a class)

2014-01-02 Thread Dominik George
Hi,

> Am I missing something or don't classes know how they're called
> (unlike funcs, which have a __name__ attribute, very practicle)? Is
> there a way to get it otherwise?

The class has it, the instance doesn't. That said, you are looking for 
self.__class__.__name__ ...

> class SuperType:
> # ...
> def __repr__ (sef):
> return "%s(stuff)" % (self.__class__.__name__, stuff)

... which you do use here.

> But I need each class to know its name. Subtypes are actually
> defined by users (of a lib), presently they are forced to write the
> name explicitely, which is stupid since they already give it as var
> name:
> 
> class SubType (SuperType):
> __name__ = "SubType"
> # 

I do not get it. The __class__.__name__ thing works great for me:

  >>> class Foo():
  ... def whoami(self):
  ... return self.__class__.__name__
  ...
  >>> f = Foo()
  >>> f.whoami()
  'Foo'
  >>> class Bar(Foo):
  ... pass
  ... 
  >>> b = Bar()
  >>> b.whoami()
  'Bar'

Please be a bit more specific about your problem, because the problem
you described obviously does not exist ;).

-nik

-- 
* mirabilos is handling my post-1990 smartphone *
 Aaah, it vibrates! Wherefore art thou, demonic device??

PGP-Fingerprint: 3C9D 54A4 7575 C026 FB17  FD26 B79A 3C16 A0C4 F296


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


Re: [Tutor] Finding the latest file in a dir

2014-01-05 Thread Dominik George
Hi,

> OSError: [Errno 2] No such file or directory: 'alfresco20140104-.sql'

> I get results if I do it without giving the dir location such as

That is because the getctime call will run based in the current working
directory. You can use a construct like:

  max([os.path.join('opt', 'foo', x) for x in os.listdir(os.path.join('opt', 
'foo')], key=os.path.getctime)

That uses a list comprehension to prepend the full path to the results.
You could also chdir() to the location beforehand.

Please always use os.path.join().

-nik

-- 
 Auf welchem Server liegt das denn jetzt…?
 Wenn es nicht übers Netz kommt bei Hetzner, wenn es nicht
gelesen wird bei STRATO, wenn es klappt bei manitu.

PGP-Fingerprint: 3C9D 54A4 7575 C026 FB17  FD26 B79A 3C16 A0C4 F296


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


Re: [Tutor] Python GPIO Code Help Needed

2014-10-26 Thread Dominik George
Hi,

>if ( GPIO.input(23) == False ):
>os.system('mpg321 -g 95 a.mp3')

while not GPIO.input(23):
pass

... would be the simplest solution.

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


Re: [Tutor] Auto-response for your message to the "Tutor" mailing list

2014-10-26 Thread Dominik George
Hi,

Am 26. Oktober 2014 13:20:13 MEZ, schrieb tutor-boun...@python.org:
>Your message for tutor@python.org, the Python programming tutor list,
>has been received and is being delivered.  This automated response is
>sent to those of you new to the Tutor list, to point out a few
>resources that can help with answering your own questions, or improve
>the chances of getting a useful answer from the other subscribers.

why is it I get this messages repeatedly despite having been reading and 
writing on the list for over a year now?

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


Re: [Tutor] How to use a function

2015-01-19 Thread Dominik George
Hi,

> parser_illumina_readset_file("~/Desktop/file.csv")
> 
> dir()
> 
> I can't found the readsets list. Someone could please help me? 
> thanks so much!

Maybe:

readsets = parser_illumina_readset_file("~/Desktop/file.csv")

In your call, you discard the result, which, obviously, discards it.

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