Re: [Tutor] Insert time into email

2014-10-20 Thread ChrisKwpolskaWarrick
Forwarding to list — please use Reply All… next time.

On Mon, Oct 20, 2014 at 6:28 PM, Crush  wrote:
> Where does the ."format(time=t,date=d)" go?
>
> I would assume something like
>
> msgTime = MIMEText()
> msgTime.add_header('not sure what to put here?' '' .format(time=t))
> msgRoot.attach(msgTime)
>
> then in the actual html, something like...
> {time}?
>
> and yes, for simplicity sake, the date and time will be the same.

Do not bother with MIME for this.  It WON’T be simpler.  (it’s most
likely impossible, in fact.)

msgText = MIMEText('…rest of your
HTML here, complete with {time} and {date}
tags…'.format(time=t, date=d), 'html')
msgAlternative.attach(msgText)

-- 
Chris “Kwpolska” Warrick <http://chriswarrick.com/>
PGP: 5EAAEA16
stop html mail | always bottom-post | only UTF-8 makes sense
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Insert time into email

2014-10-20 Thread ChrisKwpolskaWarrick
On Mon, Oct 20, 2014 at 2:34 PM, Bo Morris  wrote:
> hello all, hope everyone is doing well.
>
> The below code works, however I am going back and trying to enter the time
> and date and I cant quite figure out how to do this without breaking the
> code.
>
> #!/usr/bin/python
>
> import smtplib
> from email.MIMEMultipart import MIMEMultipart
> from email.MIMEText import MIMEText
> from email.MIMEImage import MIMEImage
> import time
>
> strFrom = "HourlyReport.com"

PS. You may want to use a real e-mail address here.  Or, at the very
least, something that looks like one.

> #strTo = "engineer...@oneconnxt.com"
> #strTo = "mmed...@onemediacorpinc.com"
> strTo = "b...@onemediacorpinc.com"
>
> l = ['3102EHD-01108.png', '3102DHD-01109.png','3102EHD-01082.png',
> '3102DHD-01033.png', '3102EHD-01302.png', '3102DHD-01149.png',
> '3102EHD-01125.png', '3102DHD-01144.png', '3102EHD-01105.png']
>
> t = time.strftime("%H:%M:%S")
> d = time.strftime("%d/%m/%Y")
>
> msgRoot = MIMEMultipart('related')
> msgRoot['Subject'] = 'Test Hourly Report'
> msgRoot['From'] = strFrom
> msgRoot['To'] = strTo
> msgRoot.preamble = 'This is a multi-part message in MIME format.'
>
> msgAlternative = MIMEMultipart('alternative')
> msgRoot.attach(msgAlternative)
>
> msgText = MIMEText('This is the alternative plain text message.')
> msgAlternative.attach(msgText)
>
> msgText = MIMEText(' src="cid:3102EHD-01108.png" width="400"
> height="300">TIMEDATE src="cid:3102DHD-01109.png" width="400"
> height="300">TIMEDATE cellspacing="15" border="1"> width="400"
> height="300">TIMEDATE src="cid:3102DHD-01033.png" width="400"
> height="300">TIMEDATE cellspacing="15" border="1"> width="400"
> height="300">TIMEDATE src="cid:3102DHD-01149.png" width="400"
> height="300">TIMEDATE cellspacing="15" border="1"> width="400"
> height="300">TIMEDATE src="cid:3102DHD-01144.png" width="400"
> height="300">TIMEDATE cellspacing="15" border="1"> width="400"
> height="300">TIMEDATE',
> 'html')
> msgAlternative.attach(msgText)
>
> for image in l:
> with open(image, 'rb') as fh:
> msgImage = MIMEImage(fh.read())
> msgImage.add_header('Content-ID', '<{0}>'.format(image))
> msgRoot.attach(msgImage)
>
>
> try:
>smtpObj = smtplib.SMTP('localhost')
>smtpObj.sendmail(strFrom, strTo, msgRoot.as_string())
>print "Successfully sent email"
> except smtplib.SMTPException:
>print "Error: unable to send email"
>
> I need to enter the time and date in the html where "TIME" and "DATE" are. I
> imagine I can do this by adding "cid: t" and "cid:d" which just refers back
> to t = "time.strftime("%H:%M:%S")" "d = time.strftime("%d/%m/%Y")"?

No, not really.  cid: is for images.  You want to insert actual text.
Use string formatting.

'…snip…{time}{date}…snip…'.format(time=t, date=d)

This is assuming every date is the same.  If it isn’t, you’d have to
use different identifiers and values.

-- 
Chris “Kwpolska” Warrick <http://chriswarrick.com/>
PGP: 5EAAEA16
stop html mail | always bottom-post | only UTF-8 makes sense
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] how to express shift+enter in python

2014-09-28 Thread ChrisKwpolskaWarrick
On Sun, Sep 28, 2014 at 4:53 PM, lei yang  wrote:
> Hi expert,
>
> How to express shift+enter in python ?
>
> Thanks

What do you want to express, exactly?  This key combination can have
multiple meanings and ways to achieve it, depending on your needs.  Do
you want to send the key combination to an app?  What is it, exactly,
that you want to do?  What app uses Shift+Enter in the way you want to
use it?

-- 
Chris “Kwpolska” Warrick <http://chriswarrick.com/>
PGP: 5EAAEA16
stop html mail | always bottom-post | only UTF-8 makes sense
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] This is driving my crazy! My file hasn't been corrupted

2014-08-31 Thread ChrisKwpolskaWarrick
On Sun, Aug 31, 2014 at 6:31 PM, Richard Dillon  wrote:
> My text file has five numbers, 1-5
> I don't what the problem is.
> I've written the file using Word (saved as .txt ) as well as TextEdit
> Python 3.4.1 on a Mac

We don’t really know either, without seeing the file.  It probably has
some unwanted garbage produced by your fancy-schmancy editor.  Get a
real plain text editor (TextWrangler for example) and don’t use
rich-text editors.  With a real editor, your code works here.

Also, don’t do this:

> except:
> print('An error occured.')

It’s better to let Python show the exceptions.

-- 
Chris “Kwpolska” Warrick <http://chriswarrick.com/>
PGP: 5EAAEA16
stop html mail | always bottom-post | only UTF-8 makes sense
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Python 3.4.1 question for Mac users

2014-08-29 Thread ChrisKwpolskaWarrick
Sorry for the errorneous quote-only response, gmail managed to send it
without me typing a thing.

On Fri, Aug 29, 2014 at 5:01 PM, Richard Dillon  wrote:
> infile = open(r'\OS\Users\richarddillon\Desktop\my_file','r')

On the Mac, you don’t need to specify a drive there; the main drive is just /.

Also, the path separator is a forward slash (/).  This also lets you
remove the r in front of the string, which is needed for backslashes
unless you escape them.  The corrected code is:

infile = open('/Users/richarddillon/Desktop/my_file', 'r')

-- 
Chris “Kwpolska” Warrick <http://chriswarrick.com/>
PGP: 5EAAEA16
stop html mail | always bottom-post | only UTF-8 makes sense
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Python 3.4.1 question for Mac users

2014-08-29 Thread ChrisKwpolskaWarrick
On Fri, Aug 29, 2014 at 5:01 PM, Richard Dillon  wrote:
> I’m teaching myself Python 3.4.1 on a Mac and the book I’m using is written
> for Windows users.
>
> I’m trying to open a file on the desktop and I created a path using the
> example in the book.
>
>
>
> Any Mac users out there with a solution? My main drive is named “OS”.
>
> Here’s my code:
>
>
>
> def main():
>
> my_file = input('Enter file to open: ')
>
> infile = open(r'\OS\Users\richarddillon\Desktop\my_file','r')
>
> file_contents = infile.read()
>
> infile.close()
>
> print(file.contents)
>
>
>
> main()
>
>
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor
>



-- 
Chris “Kwpolska” Warrick <http://chriswarrick.com/>
PGP: 5EAAEA16
stop html mail | always bottom-post | only UTF-8 makes sense
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] debug and execute python code in Mac

2014-08-28 Thread ChrisKwpolskaWarrick
On Thu, Aug 28, 2014 at 2:41 PM, William Ray Wing  wrote:
> On Aug 27, 2014, at 8:08 PM, Sebastian Silva  
> wrote:
>> Too bad it's mac only. If you try it, do share your experience. I don't use 
>> non-free operating systems, so I can't try it myself.
>
> Just as an aside — Apple has stopped charging for OS-X.

Sebastan probably meant “free” as in Stallman:
http://www.gnu.org/philosophy/free-sw.html

(most people believe free = $0.  FSF people, however, want to steal
that word for their concept.  Not very successful at that, as you can
see.)

-- 
Chris “Kwpolska” Warrick <http://chriswarrick.com/>
PGP: 5EAAEA16
stop html mail | always bottom-post | only UTF-8 makes sense
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] time vs. timeit

2014-08-26 Thread ChrisKwpolskaWarrick
On Tue, Aug 26, 2014 at 6:26 AM, diliup gabadamudalige
 wrote:
> Hi all,
>
> 1. why do some say that the time module is more accurate than the timeit
> module?
> s = time.time()
> or
> s = timeit.timeit()
>
> 2. Why is it that both modules never return the same answer on each run?

The two functions have completely different uses, and do completely
different things.

>>> help(time.time)
Help on built-in function time in module time:

time(...)
time() -> floating point number

Return the current time in seconds since the Epoch.
Fractions of a second may be present if the system clock provides them.


In other words, return this: http://en.wikipedia.org/wiki/Unix_time


>>> help(timeit)
NAME
timeit - Tool for measuring execution time of small code snippets.

[…]
 |  timeit(self, number=100)
 |  Time 'number' executions of the main statement.
 |
 |  To be precise, this executes the setup statement once, and
 |  then returns the time it takes to execute the main statement
 |  a number of times, as a float measured in seconds.  The
 |  argument is the number of times through the loop, defaulting
 |  to one million.  The main statement, the setup statement and
 |  the timer function to be used are passed to the constructor.

-- 
Chris “Kwpolska” Warrick <http://chriswarrick.com/>
PGP: 5EAAEA16
stop html mail | always bottom-post | only UTF-8 makes sense
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Preparing virtualenvwrapper for Django 1.6 development

2014-08-24 Thread ChrisKwpolskaWarrick
On Sat, Aug 23, 2014 at 9:37 PM, Alan Gauld  wrote:
> While I wouldn't say its the best environment I don't think its
> fair to say Windows is "a bad environment for Python". Any
> experienced Windows programmer will find it much easier to use Python on
> Windows than to learn a whole new OS and development environment.

There are various pitfalls that happen on Windows and that don’t on
Linux.  Some packages outright assume Windows does not exist, and this
leads to failing code.  In other cases, you must compile a C
extension, which is not easy to configure — and not ever package has
wheels/.exes available…  Linux tries to follow POSIX standards, and
also acknowledges people may want to be programmers.

Also, OP did not state whether they are experienced Windows
programmers, experienced platform-independent programmers or newcomers
to programming in general.

> [ And for context, I run Linux on my main desktop, MacOS on my
> laptop, and Windows 8.1 on a second desktop - used mainly for
> photography/video processing. And I use Python on all 3 of them)

context: I have a dual-boot Arch Linux/Windows 7 system.  Python
installed on both OSes (and even in some Windows VMs).

-- 
Chris “Kwpolska” Warrick <http://chriswarrick.com/>
PGP: 5EAAEA16
stop html mail | always bottom-post | only UTF-8 makes sense
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Preparing virtualenvwrapper for Django 1.6 development

2014-08-23 Thread ChrisKwpolskaWarrick
On Fri, Aug 22, 2014 at 11:23 PM, Sithembewena Lloyd Dube
 wrote:
> Hi everyone,
>
> I am developing on a Windows 8.1 machine and wold like to setup
> virtualenvironment via virtualenvwrapper so as to have a properly set up
> Python development environment.
>
> I am referring to Jeff Knupp's guide at
> http://www.jeffknupp.com/blog/2013/12/18/starting-a-django-16-project-the-right-way/
>
> After installation of virtualenvwrapper via pip, the guide says:
> "
> After it's installed, add the following lines to your shell's start-up file
> (.zshrc, .bashrc, .profile, etc).
>
> export WORKON_HOME=$HOME/.virtualenvs
> export PROJECT_HOME=$HOME/directory-you-do-development-in
> source /usr/local/bin/virtualenvwrapper.sh
> "
>
> My issue is, I do not understand what these lines are doing (I have a vague
> idea but assumptions can be deadly). Moreover, it is clear that the
> instructions were authored with a UNIX environment in mind.
>
> Would anyone be so kind as to translate this to Windows speak, as well as
> perhaps pointing out what file this would go into in a Windows environment?

virtualenvwrapper does not work in Windows.  You should use regular
virtualenv instead.  Read this:
http://virtualenv.readthedocs.org/en/latest/virtualenv.html#usage

Note that this blog post is HEAVILY *nix-specific, and that Windows is
a bad environment for Python development (especially Web development).
I personally recommend you just get a virtual machine running some
Linux instead of playing with Windows.

-- 
Chris “Kwpolska” Warrick <http://chriswarrick.com/>
PGP: 5EAAEA16
stop html mail | always bottom-post | only UTF-8 makes sense
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Alert to all Experienced Python Software Object Oriented Programmers-Novice Needs Help In Understanding Textbook

2014-08-17 Thread ChrisKwpolskaWarrick
On 18 August 2014 02:45 "ALAN GAULD"  wrote:
> > At the Community College we used Python version 3.4.0 which I guess is
up to date.
>
> Yes indeed, the latest and greatest.

The “latest and greatest” is actually 3.4.1.

-- 
Chris “Kwpolska” Warrick <http://chriswarrick.com/>
Sent from my SGS3.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] read cell phone's directory?

2014-08-14 Thread ChrisKwpolskaWarrick
On 14 August 2014 17:48 "= Clayton - Tang ="  wrote:
>
> Chris, thanks for the reply. I don't have newsgroup access,

You don't need it. Use the official mailing list that is mirrored to Usenet.

Main page with subscribe link:
https://mail.python.org/mailman/listinfo/python-list

The thread in question:
https://mail.python.org/pipermail/python-list/2014-August/676375.html

> can you point me to some place where I can learn more? Do you have sample
code I can learn from? Thanks.

The thread does not have any ready answer just yet, it's currently busy
arguing about the protocol. You can Google the term “python MTP”, you may
find some answers there.
-- 
Chris “Kwpolska” Warrick <http://chriswarrick.com/>
Sent from my SGS3.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] re module

2014-08-14 Thread ChrisKwpolskaWarrick
On 14 Aug 2014 15:58 "Sunil Tech"  wrote:
>
> Hi,
>
> I have string like
> stmt = 'Patient name: Upadhyay Shyam  Date of
birth:   08/08/1988 Issue(s) to be
analyzed:  tesNurse Clinical summary:  test1 Date of
injury:   12/14/2013Diagnoses:   723.4 - 300.02 - 298.3
- 780.50 - 724.4 Brachial neuritis or radiculitis nos - Generalized
anxiety disorder - Acute paranoid reaction - Unspecified sleep disturbance
- Thoracic or lumbosacral neuritis or radiculitis, unspecifiedRequester
name:   Demo SpltycdtesttPhone #:   (213)
480-9000Medical records reviewed __ pages of medical and
administrative records were reviewed including:Criteria
used in analysis  Reviewer comments DeterminationBased on the clinical information submitted for this
review and using the evidence-based, peer-reviewed guidelines referenced
above, this request is Peer Reviewer
Name/Credentials  Solis, Test, PhDInternal Medicine AttestationContact Information Peer to Peer contact attempt 1: 08/13/2014 02:46
PM, Central, Incoming Call, Successful, No Contact Made, Peer Contact Did
Not Change Determination'
>
>
> i am trying to find the various font sizes and font face from this string.
>
> i tried
>
> print re.search("
>
> Thank you.
>
>
>
>
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor
>
Don't use regular expressions for HTML. Use lxml instead.

Also, why would you need that exact thing? It's useless. Also, this code is
very ugly, with too many s and — worse — s which should not be
used at all.

-- 
Chris “Kwpolska” Warrick <http://chriswarrick.com/>
Sent from my SGS3.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] read cell phone's directory?

2014-08-14 Thread ChrisKwpolskaWarrick
On Aug 14, 2014 9:30 AM, "= Clayton - Tang ="  wrote:
>
> Hi all,
>
> I am on WIndows and have an Android cell phone running Android 4.4.4.
>
> When I connect the phone to my PC using a micro-USB cable, the phone
appears next to the local hard drive under "This PC" window, then I can
browse the phone's directory like a regular disk. My goal is to find all
the photos on the phone then do something with the files. So I copied the
path from the File Explore navigation bar, which is 'This PC\Nexus
5\Internal storage\DCIM\Camera', but the follow code doesn't work.
>
> I get an error "W indowsError: [Error 3] The system cannot find the path
specified: 'This PC\\Nexus 5\\Internal storage\\DCIM\\Camera/*.*". Does
anyone know who to make it work?

This was recently discussed on the main list (python-list aka
comp.lang.python). Long story short, modern Android phones are using the
MTP protocol and do not behave like usual USB drives. You must use a module
that implements MTP if you want to access your phone.

> import os;

No need for a semicolon here.

--
Chris “Kwpolska” Warrick <http://chriswarrick.com/>
Sent from my SGS3.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


[Tutor] Fwd: Printing multi-line variables horizontally

2014-08-09 Thread ChrisKwpolskaWarrick
It looks ilke this WONDERFUL mailing list which does not do something
as basic as a sane Reply-to header made me send a response to the OP
only.  Here it is again:


-- Forwarded message --
From: Chris “Kwpolska” Warrick 
Date: Fri, Aug 8, 2014 at 7:36 PM
Subject: Re: [Tutor] Printing multi-line variables horizontally
To: Greg Markham 


On Aug 8, 2014 7:22 PM, "Greg Markham"  wrote:
>
> Hello,
>
> Python novice back again.  :)  I'm making progress in my learning process, 
> but struggling whenever attempting to creatively go beyond what's required in 
> the various chapter assignments.  For example, there's a simple random die 
> roller program that looks like the following:
>
>
> # Craps Roller
> # Demonstrates random number generation
>
> import random
>
> # generate random numbers 1 - 6
> die1 = random.randint(1, 6)
> die2 = random.randrange(6) + 1
>
> total = die1 + die2
>
> print("You rolled a", die1, "and a", die2, "for a total of", total)
>
> input("\n\nPress the enter key to exit.")
>
>
> I wanted to make it a little more interesting by using ascii art 
> representations of the six die.  When printing, however, they do so 
> vertically and not horizontally.  Here's a snippet of the code:
>
>

>


> die_2 = """
> .-.
> |o|
> | |
> |o|
> `-'"""
>
> print(die_1, die_2)
>
>
> So, how would I get this to display horizontally?
>
> Like so...
> .-.   .-.
> | |   |o|
> |  o  |   | |
> | |   |o|
> `-'   `-'
>
> Thanks,
>
> Greg
>
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor
>

You would need to do some extra work. Specifically, you must split the
string into lines, and print them side-by-side and line-by-line. Like
this:

die_1 = [
".-.",
"|o|",
"| |",
"|o|",
"`-'",
]

die_2 = [
".-.",
"| |",
"|  o  |",
"| |",
"`-'",
]

for l, r in zip(die_1, die_2):
print(l, r)

--
Chris “Kwpolska” Warrick <http://chriswarrick.com/>
Sent from my SGS3.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Error Handling in python

2014-07-24 Thread ChrisKwpolskaWarrick
On Thu, Jul 24, 2014 at 2:23 PM, Wolfgang Maier
 wrote:
> On 24.07.2014 14:19, Chris “Kwpolska” Warrick wrote:
>>
>>
>>>>> python test.py
>>>>> if [ $? = 0 ]; then
>>>>>   python second.py
>>>>> fi
>>>>>
>>>>> as your shell script.
>>>>
>>>>
>>>>
>>>> The [ ] and = should be doubled.
>>>
>>>
>>>
>>> ?? why that ?
>>
>>
>> Double brackets can do more:
>>
>>
>> http://stackoverflow.com/questions/2188199/how-to-use-double-or-single-bracket-parentheses-curly-braces
>>
>
> But more is not required here. What am I missing ?

It’s recommended to switch to the [[ syntax anyways, some people
consider [ deprecated.  Also, [ is actually /bin/[ while [[ lives in
your shell (and is therefore faster).

About the equals sign, == is the preferred syntax, and = is also
considered deprecated (zsh explicitly says so, bash says “only for
POSIX compatibility”.

-- 
Chris “Kwpolska” Warrick <http://chriswarrick.com/>
PGP: 5EAAEA16
stop html mail | always bottom-post | only UTF-8 makes sense
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Error Handling in python

2014-07-24 Thread ChrisKwpolskaWarrick
On Thu, Jul 24, 2014 at 2:14 PM, Wolfgang Maier
 wrote:
> On 24.07.2014 14:09, Chris “Kwpolska” Warrick wrote:
>>
>> On Thu, Jul 24, 2014 at 2:01 PM, Wolfgang Maier
>>  wrote:
>>>
>>> Try something like this (assuming bash):
>>>
>>> python test.py
>>> if [ $? = 0 ]; then
>>>  python second.py
>>> fi
>>>
>>> as your shell script.
>>
>>
>> The [ ] and = should be doubled.
>
>
> ?? why that ?

Double brackets can do more:

http://stackoverflow.com/questions/2188199/how-to-use-double-or-single-bracket-parentheses-curly-braces

-- 
Chris “Kwpolska” Warrick <http://chriswarrick.com/>
PGP: 5EAAEA16
stop html mail | always bottom-post | only UTF-8 makes sense
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Error Handling in python

2014-07-24 Thread ChrisKwpolskaWarrick
On Thu, Jul 24, 2014 at 2:01 PM, Wolfgang Maier
 wrote:
> Try something like this (assuming bash):
>
> python test.py
> if [ $? = 0 ]; then
> python second.py
> fi
>
> as your shell script.

The [ ] and = should be doubled.  But all this is not needed, all you need is:

python test.py && python second.py

However, you need to explicitly stack all the commands you want to
execute this way — so, if there are more things, `set -e` might also
be of use. (you would need an even uglier tree for `if`s.)

-- 
Chris “Kwpolska” Warrick <http://chriswarrick.com/>
PGP: 5EAAEA16
stop html mail | always bottom-post | only UTF-8 makes sense
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Error Handling in python

2014-07-24 Thread ChrisKwpolskaWarrick
On Thu, Jul 24, 2014 at 1:35 PM, jitendra gupta  wrote:
> Hi All
>
> My shell script is not throwing any error when I am having  some error in
> Python code.
>
> In this case, I dont want to run my second.py
> Even I am throwing error from my test.py, but still second.py is getting
> executed, which i dont want,

You must expilicitly ask your shell to do exit if something fails.  Like this:

~ shellTest.sh ~~~
#!/bin/bash
set -e
python test.py
python second.py
~~~

I explicitly set the shell to /bin/bash on the shebang line, and then
set the -e option to fail when a command exits with a non-zero status.

You should always have a shebang line in your shell files, and execute
them as ./shellTest.sh  (after chmod +x shellTest.sh); moreover, one
for Python files is recommended, like this: #!/usr/bin/env python

-- 
Chris “Kwpolska” Warrick <http://chriswarrick.com/>
PGP: 5EAAEA16
stop html mail | always bottom-post | only UTF-8 makes sense
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] How to Create Webpage with Python

2014-07-15 Thread ChrisKwpolskaWarrick
On Jul 15, 2014 3:17 AM, "John Cast"  wrote:
>
> Hey everyone,
>
> I really appreciate all of the help you given me.
> I am making progress, however I have reached a problem I'm not sure how
best to tackle and would like someone with more experience with excel and
python to lend their knowledge/opinion before I dive in further.
>
> I have two questions:
> 1) I'd like to be able to do a 'save-as web page' in python for my excel
workbook.  I tried this by hand and everything looks good EXCEPT that the
header cells sometimes were too narrow (because the person who created the
workbook didn't expand out each column enough sometimes) and thus blocked
some of the text in them occasionally.
> Is it possible to do a 'save-as web page' for the workbook in python?
>
> 2)  So (assuming I can do this 'save-as webpage' in code) I need to go
through each sheet in the workbook and change each column's width so that
it can hold all of its text.  I realize that xlrd is for reading and xlwt
is for writing and there is xutils for particular combinations of both
reading and writing.  However, nothing to do quite what I've stated as far
as I can tell (so far).  I currently open the workbook I want to modify
using the open_workbook functionality in the xlrd module.  As I understand
it I need the xlwt module to write to this workbook, but since it's opened
in xlrd do I just open the same workbook in xlwt again?  If so does each
module simply have a handle to the same file?
>
> NOTE: I'm basically just trying to present my excel workbook on the web
as it's shown in excel (retaining as much formatting as possible).
>
> Thanks again,
> John

If you want to have output that's very close to Excel’s, why not just use
Excel’s save as webpage capabilities? You can automate that, with Python or
something else (like Excel macros or Windows-specific automation software).
It's much easier to do it this way, and it guarantees good output without
much effort.

-- 
Chris “Kwpolska” Warrick <http://chriswarrick.com/>
Sent from my SGS3.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] How to Create Webpage with Python

2014-07-11 Thread ChrisKwpolskaWarrick
On Fri, Jul 11, 2014 at 4:07 AM, John Cast  wrote:
> For future reference (assuming everything else goes well) how do I procure a
> more permanent server (i.e. one that doesn't run on my machine so that I can
> turn it off and still be able to visit my pages)?  I'm hearing Apache and so
> forth being thrown around (I've read up a little on it) but it seems those
> would still run on my local computer.
> What am I missing?

Apache is a HTTP daemon, as in a piece of software that serves content
over HTTP.  It’s one of many HTTP daemons (web servers) on the market,
and perhaps the most popular one (other popular ones are nginx and
IIS)

But if you want to host persistently, you need to get an actual
server, a piece of hardware, that runs a HTTP daemon.  There are
basically three types of servers: shared (many people host their
websites on the same machine), VPS (virtual private server), and
dedicated (a machine only for you).  Shared servers are the cheapest,
and the best idea for small/static websites.  You can even find free
shared hosting services, like GitHub Pages
<https://pages.github.com/>, or ultra-cheap ones (like
<http://NearlyFreeSpeech.net/>).

On Fri, Jul 11, 2014 at 6:21 AM, Danny Yoo  wrote:
> The ones I use for my personal and professional use are webfaction.com and
> appengine.google.com.  I'm sure others can give more suggestions.

Both are services used for hosting webapps, not static websites.

-- 
Chris “Kwpolska” Warrick <http://chriswarrick.com/>
PGP: 5EAAEA16
stop html mail | always bottom-post | only UTF-8 makes sense
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] How to Create Webpage with Python

2014-07-10 Thread ChrisKwpolskaWarrick
On Thu, Jul 10, 2014 at 6:40 PM, Alex Kleider  wrote:
> If all you want is to check how your 'site' looks perhaps it'd be much
> simpler to simply point your browser to your parent html file rather than
> set up a server machine to serve it:
> file:///home/yourusername/yoursubdirectory/index.html
> It'll look exactly the same as it would if you were running it on a server.
> (or am I missing something?)

JavaScript may not work.  The same might also happen with links and
resources using the // scheme (//example.com/ instead of
http://example.com/)

For local testing, use

python -m SimpleHTTPServer

or, if you’re on Python 3,

    python3 -m http.server

-- 
Chris “Kwpolska” Warrick <http://chriswarrick.com/>
PGP: 5EAAEA16
stop html mail | always bottom-post | only UTF-8 makes sense
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] How to Create Webpage with Python

2014-07-10 Thread ChrisKwpolskaWarrick
On Thu, Jul 10, 2014 at 3:30 AM, John Cast  wrote:
> I'm in unfamiliar territory with the web stuff, but it sounds so far like I
> will generate an HTML doc every time I run my script and then somehow turn
> that HTML doc into a static site?  (My terminology is weak here I'm sure)

If you go with the static website route, you will have to:

(a) generate a reStructuredText/Markdown/HTML file that your static
site generator (like Pelican, or Nikola* <http://getnikola.com/>) will
turn into a nice, pretty website for you, or
(b) just generate one HTML file, skipping the “static site generator” part.

> Web - Currently it looks like maybe static HTML page(s) generated every time
> my script is run is the right way to go?

Yes — it’s generally easier and nicer to do this, unless you were to
run your script very, VERY often.

>   It sounds like I need a server on my desktop?
>   I need to create a site and host/serve this somehow using my
> server?

Hosting websites off a desktop can be troublesome.  Your computer must
stay on all the time (or at least at the times when the website should
be accessible), you have to get a static IP, or use a dynamic DNS
service, and that’s assuming your ISP won’t hate you for hosting a
website.  It might be better to use an actual server instead.

>   I don't need a webframework to do this?

If you’re staying with static webpages, then yes.

* disclaimer: I’m quite involved with Nikola’s development; however,
even with that aside, I believe Nikola is much more human-friendly
than Pelican.  To each their own, though.

-- 
Chris “Kwpolska” Warrick <http://chriswarrick.com/>
PGP: 5EAAEA16
stop html mail | always bottom-post | only UTF-8 makes sense
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Doubts about installing python3.1 in squeeze

2014-05-22 Thread ChrisKwpolskaWarrick
On Thu, May 22, 2014 at 8:41 PM, C Smith  wrote:
> Sorry, typing is hard.
> *You will need to use virtualenv
>
> On Thu, May 22, 2014 at 2:40 PM, C Smith  wrote:
>> You can't use apt-get or similar to install 3.1.
>> You will need to virtualenv.

…or maybe not.  The correct way is compiling it on your own (the usual
Unix way, but using `make altinstall` for the install step).
virtualenv won’t help in this case, it’s not what virtualenv is for.

-- 
Chris “Kwpolska” Warrick <http://kwpolska.tk>
PGP: 5EAAEA16
stop html mail | always bottom-post | only UTF-8 makes sense
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Option on How to create web Interface

2014-05-22 Thread ChrisKwpolskaWarrick
On Thu, May 22, 2014 at 12:54 AM, Alan Gauld  wrote:
> But basically this just creates a text file in a folder somewhere.
> Its only when that is accessed via a web server that it gets
> sent to a browser, and only as a static file.
>
> If you wanted to do it dynamically you'd have a file called
> something like mypage.cgi which looked like:
>
> print("My web page")
> print("This the body")
>
> And provided the web server was configured to run python
> on cgi files you could access it as
>
> http://myserver.addresss/mypage.cgi

Sadly, this is not the modern way to do it.  These days, it’s
recommended to use something like Flask, or Django, or whatnot.  CGI
is ancient, and problematic.

-- 
Chris “Kwpolska” Warrick <http://kwpolska.tk>
PGP: 5EAAEA16
stop html mail | always bottom-post | only UTF-8 makes sense
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] HELP! How do I remove the black after "s="

2014-05-10 Thread ChrisKwpolskaWarrick
On Sat, May 10, 2014 at 8:35 AM, 1 2  wrote:
> In the result it shows "s= 8" pls tell me how to remove the blank?
>
> s,t,n = 0,0,1
> while t <= s:
> s,t,n = s+2,t+n,n+1
> else:
> print('s=',s,n)

You must use something else.  For example:

print('s={0} {1}'.format(s, n))

This will produce "s=8 5".  If you want "s=85", remove the space in
the format string.

-- 
Chris “Kwpolska” Warrick <http://kwpolska.tk>
PGP: 5EAAEA16
stop html mail | always bottom-post | only UTF-8 makes sense
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Advice needed by a new to Python but abit experience software dev

2014-05-04 Thread ChrisKwpolskaWarrick
On Sat, May 3, 2014 at 1:51 AM, Muhammed Salman  wrote:
> Hi,
>
> I have to develop a simple web app. In which i have to create, update, read
> and delete people. I also should be able to make people friends and best
> friends with each other. Now, (obviously) I do not want you guys to do this
> project for me ;). But what I want is that maybe you guys can give me some
> hints about where to start and make my journey easy by giving me some good
> pointers on what to look for and what not to. The technologies I have to use
> for this project are mentioned below :
>
> Flask
> SQLAlchemy
> PostgreSQL
> Git  +  Github
> WTForms
> Heroku
> Bootstrap
> pytest

That’s kinda advanced — and far beyond the target of this list.  You
are better off by asking the main Python mailing list, at
https://mail.python.org/mailman/listinfo/python-list — also available
as comp.lang.python on Usenet.  You should start by reading the
documentation for Flask, Flask-WTF and Flask-SQLAlchemy.  All three
have awesome, extensive documentation that will help you out greatly
and help you get started.  (requires Python skills, which you should
get from the official Python tutorial if you are an experienced
developer.)

Also, Bootstrap is a front-end framework: http://getbootstrap.com/ —
and you’re better off asking HTML/CSS people for advice, after you
read the extensive docs.

-- 
Chris “Kwpolska” Warrick <http://kwpolska.tk>
PGP: 5EAAEA16
stop html mail | always bottom-post | only UTF-8 makes sense
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Final review

2014-05-01 Thread ChrisKwpolskaWarrick
On Thu, May 1, 2014 at 7:21 AM, Scott W Dunning  wrote:
> Hello, I am new to python and have a final review coming up and was hoping 
> you could help me answer a few questions I came across while studying.
>
>
> So, I get a little confused about lists sometimes.  This one is a little hard 
> to make heads or tails of.  I get confused about how to tell how many lists 
> are within one list like the one below.   How many lists are located inside 
> alist is it 1 or 2, 3??

Two: [56, 57, "dog"] and [] (empty).

> Also, do spaces count as an index in lists?

What do you mean by “spaces”, exactly?

>>>> alist = [3, 67, "cat”, [56, 57, “dog”], [], 3.14, False]

alist contains:

0. the integer 3
1. the integer 67
2. the string "cat" ¹
3. the list:
   0. the integer 56
   1. the integer 57
   2. the string "dog" ¹
4. an empty list
5. the float 3.14
6. the boolean False

¹ Your e-mail client uses smart quotes and thus mangles your replies
(it converts U+0022 QUOTATION MARK into U+201C LEFT DOUBLE QUOTATION
MARK and U+201D RIGHT DOUBLE QUOTATION MARK, which are not valid
delimiters for Python strings).

> The ouput for below is 2 when it seems like there should be 3 lists located 
> inside x.  Is it [10,20] that is not consider inside of x?Any tips on how 
> to tell how to spot them more clearly?

There are two lists in x, and one more list inside a list inside of x:

> x = ['a', [2.0, 5, [10, 20]]]

x contains:

0. the string 'a'
1. the list:
   0. the float 2.0
   1. the integer 5
   2. the list:
  0. the integer 10
  1. the integer 20

-- 
Chris “Kwpolska” Warrick <http://kwpolska.tk>
PGP: 5EAAEA16
stop html mail | always bottom-post | only UTF-8 makes sense
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] conditional execution

2014-04-01 Thread ChrisKwpolskaWarrick
On Tue, Apr 1, 2014 at 6:07 PM, Patti Scott  wrote:
> I've been cheating:  comment out the conditional statement and adjust the
> indents. But, how do I make my program run with if __name__ == 'main':
> main() at the end?  I thought I understood the idea to run a module called
> directly but not a module imported.  My program isn't running, though.

The statement is:

if __name__ == '__main__':

You’re missing the double underscores on both sides of __main__.  If
you added them in, this would work.

> Below is the last textbook example (Python Programming, Zelle) I reworked.
> Runs when I comment out the conditional statement.  I am self-studying.
> Python 2.7.3,  Notepad++,  Windows PowerShell.
>
> # calc.pyw
> # a 4-function calculator that uses Python arithmetic
> # illustrates use of objects and lists to build a simple GUI
>
> from graphics import *
> from button import Button
>
> class Calculator:

It’s better to inherit from object (i.e. use `class
Calculator(object):`) in this case.  Saves you a lot of trouble when
you encounter new-style-only things.

> # this class  implements simple calculator GUI
>
> def __init__(self):
> # create window for calculator
> win = GraphWin('calculator')
> win.setCoords(0,0,6,7)
> win.setBackground('slategray')
> self.win = win
> # now create the widgets
> self.__createButtons()
> self.__createDisplay()
>
> def __createButtons(self):
> # create list of buttons
> # start with all the standard-sized buttons
> # bSpecs gives center coords and labels of buttons
> bSpecs = [(2,1,'0'), (3,1,'.'),
> (1,2,'1'), (2,2,'2'), (3,2,'3'), (4,2,'+'), (5,2,'-'),
> (1,3,'4'), (2,3,'5'), (3,3,'6'), (4,3,'*'), (5,3,'/'),
> (1,4,'7'), (2,4,'8'), (3,4,'9'), (4,4,'<-'), (5,4,'C')]
> self.buttons = []
> for (cx,cy, label) in bSpecs:
> self.buttons.append(Button(self.win, Point(cx,cy), .75,.75,
> label))
> # create the larger equals button
> self.buttons.append(Button(self.win, Point(4.5,1), 1.75, .75, '='))
> # activate all buttons
> for b in self.buttons:
> b.activate()
>
> def __createDisplay(self):
> bg = Rectangle(Point(.5,5.5), Point(5.5, 6.5))
> bg.setFill('white')
> bg.draw(self.win)
> text = Text(Point(3,6), "")
> text.setFace('courier')
> text.setStyle('bold')
> text.setSize(16)
> text.draw(self.win)
> self.display = text
>
> def getButton(self):
> # waits for button to be clicked and returns label of that button
> while True:
> p = self.win.getMouse()
> for b in self.buttons:
> if b.clicked(p):
> return b.getLabel()  # method exit
>
> def processButton(self, key):
> # updates calculator display for press of this key
> text = self.display.getText()
> if key == 'C':
> self.display.setText("")
> elif key == "<-":
> # backspace, slice off the last character
> self.display.setText(text[:-1])
> elif key == '=':
> # evaluate the expression and display result
> # the try ... except mechanism catches errors in the
> #formula being evaluated
> try:
> result = eval(text)
> except:
> result ='ERROR'
> self.display.setText(str(result))
> else:
> # normal key press, append it to end of display
> self.display.setText(text+key)
>
> def run(self):
> # infinite event loop to process button clicks
>     while True:
> key = self.getButton()
> self.processButton(key)
>
> #this runs the program
> if __name__ == 'main':
> #first create a calulator object
> theCalc = Calculator()
> # now call the calculator's run methond
> theCalc.run()
>
>
>
> and I get
>
> PS C:\Users\Owner\Py Programs> python calc.py
> PS C:\Users\Owner\Py Programs>
>
>
>
> Thanks
>
>
>
>
>
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor
>



-- 
Chris “Kwpolska” Warrick <http://kwpolska.tk>
PGP: 5EAAEA16
stop html mail | always bottom-post | only UTF-8 makes sense
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Help Noob Question

2014-03-28 Thread ChrisKwpolskaWarrick
On Fri, Mar 28, 2014 at 2:17 AM, Alan Gauld  wrote:
> On 27/03/14 21:01, Chris “Kwpolska” Warrick wrote:
>> Painful? How painful can `cd Desktop` be? Certainly less than `D:`
>> followed by `cd PythonProjects`…
>
>
> Because the desktop is hardly ever anywhere near where the cmd prompt lands
> you.

I just tested on my Windows 7 box.  It got me to C:\Users\Kwpolska.
`cd Desktop` is enough.
I also tested on a third-party’s XP box.  C:\Documents and
Settings\[username].  `cd Desktop`, too (though it’s
locale-dependent).

Does not look far from the desktop, does it?

Well, the only places where this might not work are Administrator
prompts in Vista-and-newer (which there is NO REAL REASON to use for
Python) — or possibly some ultra-crazy corporate environments (but you
should not be learning Python there — and if you are working there,
you know how to work with the command line/Windows/source control
already).  Or, of course, systems where you changed something and it
is not your profile directory — but it’s your doing.  So, it’s pretty
much the home directory everywhere you should be concerned with.

> you have to remember where it is. There is no ~ shortcut in Windows.
> On my system that means typing something like:
>
> C:\Documents and Settings\alang\Desktop

or just cd %USERPROFILE%.  Different drives would make you jump to
%HOMEDRIVE% and then to %HOMEPATH%.

>>
>>
>> Can't you make a symlink pointing to Desktop? (in C:\ or anywhere else)
>
>
> You could, and that would help a little. But the problem on Windows is that
> what appears on the Desktop *display* is an amalgam of (up to 3?) different
> folders in the file system. So just because you see an icon on the 'desktop'
> doesn't mean you actually know which folder it is in.

But, for user-created files, it always goes to %USERPROFILE%/Desktop.

> Secondly this correlation between desktop folder and desktop display means
> that's a bad place to store python files since every file you create will
> add to the clutter of icons on your display. In my python projects file I
> have over 100 small test files. That would be a
> lot of icons messing up my screen.

Create a folder on the desktop, or even in the home directory.  A much
nicer place than the drive root — and a much modern way to store it
(drive root sounds DOS-y)

-- 
Chris “Kwpolska” Warrick <http://kwpolska.tk>
PGP: 5EAAEA16
stop html mail | always bottom-post | only UTF-8 makes sense
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Help Noob Question

2014-03-27 Thread ChrisKwpolskaWarrick
On Mar 27, 2014 8:58 PM, "Alan Gauld"  wrote:
>
> On 27/03/14 06:43, Leo Nardo wrote:
>>
>> Im on windows 8 and i need to open a file called string1.py that is on
>> my desktop,
>
>
> Thats your first problem. Its usually a bad idea to store your python
code on the desktop, because the desktop is a pain to find from a command
line.

Painful? How painful can `cd Desktop` be? Certainly less than `D:` followed
by `cd PythonProjects`…

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


Re: [Tutor] Why does the last loop not work?

2014-02-25 Thread ChrisKwpolskaWarrick
On Tue, Feb 25, 2014 at 1:59 AM, Gregg Martinson
 wrote:
> # problem is that myTeams has no value outside of the loop
> for x in myTeams:
> x.print_team

No, that is not the problem.  The problem is, you’re missing
parentheses there and are not executing the print_team method, just
referring to it.  Do this:

for x in myTeams:
x.print_team()

This causes this output:

[kwpolska@kw-cassandra /tmp]% python foo.py
code is:  a
code is:  aa
code is:  b
code is:  bb
code is:  c
code is:  cc
code is:  d
team code is:  a
debated: team code is:  aa
debated: team code is:  b
debated: team code is:  bb
debated: team code is:  c
debated: team code is:  cc
debated: team code is:  d
debated: [kwpolska@kw-cassandra /tmp]%

Which is kinda wrong.   But that’s the fault of your print_team() and
lack of competitors.
-- 
Chris “Kwpolska” Warrick <http://kwpolska.tk>
PGP: 5EAAEA16
stop html mail | always bottom-post | only UTF-8 makes sense
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] from command prompt use interactive python and running script together

2014-02-21 Thread ChrisKwpolskaWarrick
On Fri, Feb 21, 2014 at 3:20 PM, Gabriele Brambilla
 wrote:
> Hi,
>
> Is possible on python to running scripts from the command prompt (I'm using
> python on windows) and in the end saving all the variables and continue the
> analysis in the interactive mode? (the one that you activate typing python
> in the command prompt?)

Run this:

python -i file.py

> Or to use python in the interactive mode and in some moments to run scripts,
> without quit() the interactive mode, and use for the script variables the
> one you have defined in the interactive mode?
>
>
> thanks
>
> Gabriele
>
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor
>

-- 
Chris “Kwpolska” Warrick <http://kwpolska.tk>
PGP: 5EAAEA16
stop html mail | always bottom-post | only UTF-8 makes sense
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Regarding Exceptions

2014-02-17 Thread ChrisKwpolskaWarrick
On Mon, Feb 17, 2014 at 12:44 PM, Khalid Al-Ghamdi  wrote:
> Hi,
>
> Why is it i can use mu custom class exception without creating an exception
> object first?
>
> Thanks
>
> class ShortInputException(Exception): def __init__(self, length, atleast):
> Exception.__init__(self)
> self.length = length
> self.atleast = atleast
> try:
> text = input() if len(text) < 3:
> raise ShortInputException(len(text), 3) # Other work can continue as usual
> here
> except EOFError:
> print()
> except ShortInputException as ex:
> print(\
> .format(ex.length, ex.atleast)) else:
> print()

Hello there!

Unfortunately, the code you provided is invalid, and it seems not to
contain required indentation, newlines, and has some other things that
should break (eg. line 12)

Please reply (using Reply All!) in plaintext, with the correct code.

Also, do you mind phrasing your question more precisely?  Do you need
help with inheritance?  What is the problem you’re having?

-- 
Chris “Kwpolska” Warrick <http://kwpolska.tk>
PGP: 5EAAEA16
stop html mail | always bottom-post | only UTF-8 makes sense
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] iterators

2014-01-18 Thread ChrisKwpolskaWarrick
On Sat, Jan 18, 2014 at 9:51 AM, Keith Winston  wrote:
> I don't really get iterators. I saw an interesting example on
> Stackoverflow, something like
>
> with open('workfile', 'r') as f:
> for a, b, c in zip(f, f, f):
> 
>
> And this iterated through a, b, c assigned to 3 consecutive lines of
> the file as it iterates through the file. I can sort of pretend that
> makes sense, but then I realize that other things that I thought were
> iterators aren't (lists and the range function)... I finally succeeded
> in mocking this up with a generator:
>
> gen = (i for i in range(20))
> for t1, t2, t3 in zip(gen, gen, gen):
> print(t1, t2, t3)

For Python 2, use xrange() instead to get an iterator.  In Python 3,
range() is already an iterator.

> So I'm a little more confident of this... though I guess there's some
> subtlety of how zip works there that's sort of interesting. Anyway,
> the real question is, where (why?) else do I encounter iterators,
> since my two favorite examples, aren't... and why aren't they, if I
> can iterate over them (can't I? Isn't that what I'm doing with "for
> item in list" or "for index in range(10)")?

range() actually returns a list.  Lists are not iterators, as next(L)
would’ve told you:

In [1]: next([1, 2])
---
TypeError Traceback (most recent call last)
 in ()
> 1 next([1, 2])

TypeError: list object is not an iterator

You can, however, get an iterator of a list, by doing iter(L):

In [2]: iter([1, 2])
Out[2]: 

Moreover:

> The ``for`` statement is used to iterate over the elements of a
> sequence (such as a string, tuple or list) or other iterable object.
(from help('for'))

Basically, this is how `for i in X` works:

1. get an iterator by calling X.__iter__() (equivalent to iter(X))
2. assign `i` to X.next() (or X.__next__() in Python 3; equivalent to next(X))
3. if a `break` statement occurs anywhere, get out of the `for` block;
   elif StopIteration is raised, the `else` block is executed (if any)
 and then the program continues;
   else, go to step 2.

Here is a poor man’s pure-python re-implementation of `for`:
https://gist.github.com/Kwpolska/8488091

This should clear up most of your doubts.

-- 
Chris “Kwpolska” Warrick <http://kwpolska.tk>
PGP: 5EAAEA16
stop html mail | always bottom-post | only UTF-8 makes sense
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] print in py3

2013-12-22 Thread ChrisKwpolskaWarrick
On Sun, Dec 22, 2013 at 11:14 AM, Steven D'Aprano  wrote:
> That's the answer to your question: in Python 2, print is a statement,
> not a function. That has many consequences, but the relevant one is that
> statements don't require brackets (parentheses for Americans reading)
> around the arguments.

If Python 3 compatibility is needed/desired, one can do

from __future__ import print_function

in order to make Python 2 operate like Python 3.

> (It is commas, not parentheses, which create tuples.)

…unless you want an empty tuple, in which case it’s just () — without
any commas whatsoever.

-- 
Chris “Kwpolska” Warrick <http://kwpolska.tk>
PGP: 5EAAEA16
stop html mail | always bottom-post | only UTF-8 makes sense
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Coding for a Secret Message in a Game

2013-12-13 Thread ChrisKwpolskaWarrick
On Fri, Dec 13, 2013 at 5:10 AM, Sky blaze  wrote:
> Hi, I'm a newbie Python programmer. I was introduced to Python via the Hour
> of Code, and after completing all three of Grok Learning's tutorials, I was
> inspired to create a text-based RPG adventure. I composed this e-mail after
> searching for a forum for Python, and this address showed up in one of the
> results.
>
> Due to my inexperience with Python, I'm having trouble creating a code for
> one of the things I wanted to do for the game. The game starts out on a
> "title screen" with a message saying, "Type 'start' to begin!" I thought
> it'd be amusing to have the message change after the player types something
> other than "start" at least 10 times. I've attempted numerous times to code
> this, but all of them have failed. Could you help me with the coding? It
> should look something like this in the end:
>
>>Type "start" to begin!
>>No
>>Type "start" to begin!
>>Maybe
>>Type "start" to begin!
>>Perhaps
>>Type "start" to begin!
>>Nope
>>Type "start" to begin!
>>Why?
>>Type "start" to begin!
>>Are you sure?
>>Type "start" to begin!
>>You can't tell me what to do.
>>Type "start" to begin!
>>I'll start if I want to.
>>Type "start" to begin!
>>End
>>Y U NO TYPE "start"?!
>>Woah
>>Y U NO TYPE "start"?!
>>Okay, okay, I'll type it!
>>Y U NO TYPE "start"?!
>>start
>
> Here's the code I currently have so far:
> print("===INSTRUCTIONS===")
> input(">> ")
> print("When you see a \'>>\', hit Enter to advance the text.")
> print("When you see a \'> \', type in a command.")
> print("Commands are displayed in quotations.")
> print("Type them exactly as how they appear in quotations.")
> print("For example. Type \"hi\" to wave!")
> print("You would type hi next to the \'> \' prompt.")
> print("Now that the basics are out of the way, enjoy the game!")
> input(">> ")
> print("***SUPER GENERIC SHORT TEXT RPG ADVENTURE***")
> start = False #This is the start screen check
> print("Type \"start\" to begin.") #Command message to start the game
> start_prompt = input("> ") #Command prompt to start the game

Assuming Python 3.  If it’s python 2, do raw_input() instead.

> while start != True: #Infinite loop that doesn't end until "start" is typed
Most people tend to do “while not start:” in this case.  The reverse
would be “while start:” and this also applies to if’s.
> if start_prompt == "start":
> start = True #Continues from the title screen
> else:
> #This is where I'm stuck. I can loop it so it always returns the
> command message when
> #"start" isn't typed, but changing the message upon having that
> occur at least 10 times is
> #what's giving me trouble.

You need to count it somewhere, and test it.  With that, it becomes
fairly obvious, but with a catch: a one-off error can be easily made.
Have some code:

print("***SUPER GENERIC SHORT TEXT RPG ADVENTURE***")
start = False # This is the start screen check
print("Type \"start\" to begin.") # Command message to start the game
start_prompt = input("> ") # Command prompt to start the game
attempts = 1 # Count the start attempts made.  If you made it a zero,
that would break your example.

while not start:
if start_prompt == "start":
start = True
else:
attempts += 1
if attempts < 10:
print("Type \"start\" to begin.")
else:
print("Y U NO TYPE \"start\"?!")
start_prompt = input("> ")

-- 
Chris “Kwpolska” Warrick <http://kwpolska.tk>
PGP: 5EAAEA16
stop html mail | always bottom-post | only UTF-8 makes sense
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Cannot understand object initiation

2013-10-14 Thread ChrisKwpolskaWarrick
On Mon, Oct 14, 2013 at 3:27 PM, Kush Goyal  wrote:
> Also, db is an sqlalchemy engine and db.Model is a class.
>
> db.Model is I think a sqlalchemy declarative base class which has all
> the needed methods and classes for database handling.
>
> So, did I get the above things right?

Not quite.  db.Model is basically a representation of a database
record.  Read this:
http://docs.sqlalchemy.org/en/rel_0_8/orm/tutorial.html

Note that the above document uses the name `Base` (declarative base)
to describe what Flask-SQLAlchemy calls `db.Model`.

-- 
Chris “Kwpolska” Warrick <http://kwpolska.tk>
PGP: 5EAAEA16
stop html mail | always bottom-post | only UTF-8 makes sense
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] [OT] Replies go to individuals, not the list?

2013-08-20 Thread ChrisKwpolskaWarrick
On Tue, Aug 20, 2013 at 8:53 PM, Alan Gauld  wrote:
> On 20/08/13 13:15, Andy McKenzie wrote:
>
>> Yep.  Someone decided it didn't make sense for "reply" to go to the list
>> that sent the message
>
>
> Lists never send messages. People do.
>
> So reply goes to the *person* who sent the message.
> Which is what mail always does, to modify it for mail
> forwarded by a list server makes no sense whatsoever.
> And it breaks the ability to send to the originator.

The From: field still contains an e-mail address of a human.  Just
copy-paste it into the To: field of your reply.

And replying to the human instead of the list is almost never what you want.

-- 
Chris “Kwpolska” Warrick <http://kwpolska.tk>
PGP: 5EAAEA16
stop html mail | always bottom-post | only UTF-8 makes sense
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] How to redirect console output to a TextEdit box on a QT Python Gui ?

2013-06-21 Thread ChrisKwpolskaWarrick
On Fri, Jun 21, 2013 at 4:59 AM, SM  wrote:
>> # Replace stdout if needed
>> sys.stdout = self.oldstdout

It’s better to do it no matter what.  Otherwise, hell might break loose.

--
Kwpolska  | GPG KEY: 5EAAEA16
stop html mail| always bottom-post
http://asciiribbon.org| http://caliburn.nl/topposting.html
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Opinion - help could use more examples

2013-06-19 Thread ChrisKwpolskaWarrick
On Wed, Jun 19, 2013 at 8:11 PM, Jim Mooney  wrote:
> As for downloadable help, I have a chm file, and the Search is terrible.

Get the sane html format, where the search is more useful.

--
Kwpolska  | GPG KEY: 5EAAEA16
stop html mail| always bottom-post
http://asciiribbon.org| http://caliburn.nl/topposting.html
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Opinion - help could use more examples

2013-06-19 Thread ChrisKwpolskaWarrick
On Wed, Jun 19, 2013 at 7:43 PM, Jim Mooney  wrote:
> Here's a peeve of mine about Python help - it often has zero examples.
> I printed help(zip) to see what it does and got this:
>
>   Return a zip object whose .__next__() method returns a tuple where
>  |  the i-th element comes from the i-th iterable argument.  The .__next__()
>  |  method continues until the shortest iterable in the argument sequence
>  |  is exhausted and then it raises StopIteration.
>
> Not understandable right off, IMHO, unless you're already hardcore.
> Okay, I figured it out by running it with some iterables, so I didn't
> have to google around looking for examples. It would have saved time
> if there was just one example of what you would get from running
> next() on a zip or number lists a few times, since it's a simple
> concept. I'm coming from Jquery, which is chock full of examples, so
> everyone from bankers to pimps (if there is a difference) can use it.
> I think the name is confusing zip with compacting, too.
>
> Although to be fair.
> choosing_nth_item_from_parallel_sequences_until_there_is_no_match_on_n()
> might be too much typing compared to zip() ;')

A short explanation might be

Iterate on arguments, if all return something yield whatever we
got, otherwise stop iterating.

But anyways, instead of using the built-in docs, refer to the
human-friendly documentation available on the web:
http://docs.python.org/3/library/functions.html?highlight=zip#zip

Downloads for those docs, if you believe this would be more convenient
for you, are available at http://docs.python.org/2/download.html and
http://docs.python.org/3/download.html (for Python 2 and 3
respectively)
--
Kwpolska  | GPG KEY: 5EAAEA16
stop html mail| always bottom-post
http://asciiribbon.org| http://caliburn.nl/topposting.html
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] How to redirect console output to a TextEdit box on a QT Python Gui ?

2013-06-16 Thread ChrisKwpolskaWarrick
On Sun, Jun 16, 2013 at 7:15 PM, SM  wrote:
> Hi
> I have implemented a GUI using PyQt4/python3, which allows the user to
> select a few files as command-line arguments. When I hit "OK" button, my
> application runs and the output text is displayed on the terminal where I
> run the python script. I would like to redirect this text to a TextEdit
> window I have created on the GUI:
>
> self.textEdit = QtGui.QTextEdit(Form)
> self.textEdit.setGeometry(QtCore.QRect(10, 300, 421, 141))
> self.textEdit.setObjectName(_fromUtf8("textEdit"))
>
> Do you have any suggestions/tips as to how I can accomplish this task? Using
> some suggestions online,  I tried creating a QProcess object and connect the
> signal to a function which  reads the std output. But I don't know how to
> set the arguments to the call "process.start".
>
> self.process = QtCore.QProcess()
> QtCore.QObject.connect(self.process, QtCore.SIGNAL("readyReadStdout()"),
> self.readOutput)
> I know I have to call self.process.start here but am not able to find
> examples of how to do it. One example online uses
> "self.process.setArguments", but python3/pyQt4 doesn't seem to know about
> it. Using the argument directly with process.start is not helping either.
>
> Appreciate any pointers. If there are better ways than what I am trying to
> use, appreciate that as well.

If the application you run is a Python script, import it, execute the
functions and have the data returned (as opposed to printing it), and
then you can do self.textEdit.setText(output_goes_here)

If the application isn’t Python, use the (stock aka vanilla)
subprocess module.  The easiest solution is:

import subprocess
self.textEdit.setText(subprocess.check_output(('command',
'argument1', 'argument2')))

And you do that in the function that is called when you press OK.

Bonus suggestion: do nice layouts instead of setting the coordinates
manually.  The options you want are in the Form menu of Qt Designer.
If you don’t do this, resizing windows is nonsense.

--
Kwpolska  | GPG KEY: 5EAAEA16
stop html mail| always bottom-post
http://asciiribbon.org| http://caliburn.nl/topposting.html
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Is there a programmatic use for keys() and values()

2013-06-16 Thread ChrisKwpolskaWarrick
On Sun, Jun 16, 2013 at 7:25 PM, Jim Mooney  wrote:
> On 15 June 2013 23:30, Dave Angel  wrote:
>
 The sort() method doesn't work, but sorted does.
>
> How many times have I read you can't sort a dictionary in Python. Was
> I just misreading or was that true of older Pythons?

Dicts have no order:

>>> {'b': 'c', 'a': 'z'}
{'a': 'z', 'b': 'c'}

Moreover, the sorted() function sorts the keys only (something that
list() does anyway).  If you are looking for a way to have dicts with
an order of keys (and you don’t need that most of the time), look at
collection.OrderedDict.

--
Kwpolska  | GPG KEY: 5EAAEA16
stop html mail| always bottom-post
http://asciiribbon.org| http://caliburn.nl/topposting.html
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Hi, First question

2013-06-16 Thread ChrisKwpolskaWarrick
On Sat, Jun 15, 2013 at 7:22 AM, Patrick Williams  wrote:
> Hi so I am making a bit of code to extract a bit of numbers data from a file
> and then find the average of that data, however while I can get the code to
> extract each specific piece of data I need, I can't seem to get the numbers
> to add separately  so I can get a proper average. My sum1 variable seems to
> only take the last bit of data entered. I was just wondering if anyone knows
> what I'm doing wrong, the course I'm following hadn't started using regex
> (or even proper lists) at this point, so there must be a way to do it
> without. here's the code. the average of the data should be 0.6789 or
> something, but I get 0.0334343 or something.
>
> count=0
> lst=list()

`lst = []` is the preferred syntax.

> fname='mbox-short.txt'
> fhand=open(fname)
> for line in fhand:
> if line.startswith('X-DSPAM-Confidence:'):
> count=count+1
> colpos=line.find(':')
> zpos=line.find('0',colpos)
> num=float(line[zpos:50])
> sum1=0+num
> avg=float(sum1)/int(count)
> print 'Count-', count,'--', 'Average-', avg
>
> Any help at all is appreciated, and thanks in advance.
>
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>

I don’t know what file you used, but the message you sent got this
header from Gmail, and the format doesn’t seem to be much different:

> X-Spam-Evidence: '*H*': 0.79; '*S*': 0.00; 'separately': 0.09;
>'wrong,': 0.09; 'subject:question': 0.10; 'code.': 0.18;
>'variable': 0.18; 'bit': 0.19; 'advance.': 0.19; 'seems': 0.21;
>'8bit%:5': 0.22; 'print': 0.22; 'skip:l 30': 0.24; '\xa0so': 0.24;
> [snip 11 more lines]
(replaced tabstops with spaces)

Can you guess what’s wrong in your code?

You are reading only the first line.  There are more.  How do you
handle that?  You need to make your algorithm read all the further
lines that begin with the indentation your thing uses (it might be the
tab character '\t' or some spaces), and stop when it encounters
another header.  This can be done either by checking if the line
begins with the indentation OR by checking match with regexp
'[A-Za-z]+: .+'

--
Kwpolska  | GPG KEY: 5EAAEA16
stop html mail| always bottom-post
http://asciiribbon.org| http://caliburn.nl/topposting.html
   >
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] 2 basic problems

2013-06-16 Thread ChrisKwpolskaWarrick
On Wed, May 29, 2013 at 11:23 PM, charles benoit
 wrote:
> 1:Python 2.7.4 (default, Apr 19 2013, 18:32:33)
> [GCC 4.7.3] on linux2
> Type "copyright", "credits" or "license()" for more information.
 4+4
> 8
 3+3=4
> SyntaxError: can't assign to operator
 3=1
> SyntaxError: can't assign to literal
>>
> I thought the last 2 lines should return False

`=` is the assignment operator (`a = 2` sets the variable `a` to the
value of `2`), whereas `==` is the comparison operator.

> 2:
> lot=('1'+'6'+'8')
> print(lot)
> a=open("acc","w")
> a.write(lot)
> a.close

missing `()` here

> b=open("acc","r")
> b.read()
> print (b)

1. There should be no parenthesis here in Python 2.
2. The proper syntax is `print b.read()`.  You are reading the text
and discarding the return value (you aren’t setting a variable to it
or passing it to something else, like print), then printing the
information of what the `b` object is.

> b.close
missing `()` here, too
>
>
> returns

prints*, there is no return value


> 168
> 

>
> I thought I was saving a string to a file and reading and printing the
> string. The output looks like a description of the IO textwrapper at some
> location. I'm sure this is a syntax/format problem.but this like the other
> examples I saw. I ran this using python 2.6.7 on ubuntu 13.0  Thank you for
> any help

Please use the 2.7.4 interpreter (the same one you used for the first
example) instead.

Moreover, you could do it all in one step ('w+' stands for “clear file
and allow read/write output”, while f.seek(0) is used to return the
pointer back to the beginning of the file):

f = open('acc', 'w+')
f.write(lot)
f.seek(0)
print f.read()
f.close()

Or using the `with` syntax (a.k.a. the context manager syntax):

with open('acc', 'w+') as f:
f.write(lot)
f.seek(0)
print f.read()

--
Kwpolska  | GPG KEY: 5EAAEA16
stop html mail| always bottom-post
http://asciiribbon.org| http://caliburn.nl/topposting.html
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] What is the difference between checking false?

2013-06-16 Thread ChrisKwpolskaWarrick
On Sun, Jun 16, 2013 at 7:52 AM, Jim Mooney  wrote:
> On 15 June 2013 22:32, Steven D'Aprano  wrote:
>> http://mail.python.org/pipermail/python-list/2013-June/649710.html
>
> A succinct list - worth putting in my Keep file ;')
>
> -
> Jim
> After indictment the bacon smuggler was put on the no-fry list
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor

Another thing worthy putting there may be may be the three ways to do
`if` statements to compare stuff:

1. `if x` — runs bool(x), see list above, can be negated by `if not x`
2. `if x == y` — tests if they have the same value, negated by `if x
!= y` or `if not x == y` (not used).
3. `if x is y` — tests if they are the same object, used for `is
None`/`is not None` comparisons and not much else.
-- 
Kwpolska  | GPG KEY: 5EAAEA16
stop html mail| always bottom-post
http://asciiribbon.org| http://caliburn.nl/topposting.html
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Is there a programmatic use for keys() and values()

2013-06-15 Thread ChrisKwpolskaWarrick
On Sat, Jun 15, 2013 at 8:41 PM, Jim Mooney  wrote:
> When I try to get the keys of a dictionary, such as d.keys(), I get
> the below instead of a plain list, and it's not very usable. How can I
> use the keys from this like it was a list, or is this basically
> useless other than to see the keys or values?
>
> *** Python 3.3.2 (v3.3.2:d047928ae3f6, May 16 2013, 00:03:43) [MSC
> v.1600 32 bit (Intel)] on win32. ***
 d.keys()
> dict_keys(['alpha', 'olf', 'bog', 'dog'])

The standard use is:

for k, v in d.items():
   do_stuff_with_dict_items_here()

You can use the .keys() and .values() in a similar way.  You don’t
need a list 99% of the time.  And if you do, it is not hard to make it
one.

--
Kwpolska  | GPG KEY: 5EAAEA16
stop html mail| always bottom-post
http://asciiribbon.org| http://caliburn.nl/topposting.html
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] when is a generator "smart?"

2013-06-03 Thread ChrisKwpolskaWarrick
On Mon, Jun 3, 2013 at 8:13 PM, Jim Mooney  wrote:
>
> On 3 June 2013 07:22, Oscar Benjamin  wrote:
>
> > If you put "from __future__ import print_function" at the top of your
> > module you can use the same print function in Python 2.6/2.7 and 3.x.
> > I recommend doing this rather than bothering with the 2.x print
> > statement.
>
> Using Python 2.7 on Windows 7
>
> That's handy. When I went backward from 3.3 to 2.7, one of the few
> things I missed at my level was end= and sep= in print()  .format()
> was already backported since I'd learned that. I do like it .format()
> better unless you get too fancy with those {}s. I dislike the % format
> for some reason. It just looks ugly to me. And as it says in  first
> sentence of The Zen of Python from this.py: "Ornhgvshy vf orggre guna
> htyl."
>
> As a programming exercise I've been trying to translate Ancient
> Pythonaic back to English, but I don't follow Tim Peter's obfuscated
> little program yet. Ancient Pythonaic will probably never rival
> Klingon ;')

It is just rot13.  In Python 2, `str.decode('rot13')` would be enough.
 In Python 3, it doesn’t seem to happen so easily.  (If anyone knows
how to do it, please share!)

> Ah, question just came up. Since I have two pys, when a module is
> ported from 2.7 to 3.2 does it always have a different name?

It never does.  And in case it does, the developers are idiots.

> If the names are the same i can see where I can get confused with a pip
> install. Unless it is true that if I use pip-3.3 it will always
> install a 3.3 module, and if I use pip-2.7 it will always install a
> 2.7 module. I'd get rid of Py 3.3 for now to avoid confusion, but at
> some point, since a lot has not been ported to 3.3

http://python3wos.appspot.com/ seems to think otherwise.  60.5% of the
top 200 packages are ported, and two more are getting close
(werkzeug+flask[0]).

[0]: 
http://www.reddit.com/r/Python/comments/1fd69b/werkzeug_and_flask_git_repositories_have_early/

--
Kwpolska  | GPG KEY: 5EAAEA16
stop html mail| always bottom-post
http://asciiribbon.org| http://caliburn.nl/topposting.html
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Codeacademy Problem

2013-04-29 Thread ChrisKwpolskaWarrick
On Mon, Apr 29, 2013 at 5:28 PM, Joseph Parkton  wrote:
> I tried both suggestions from Chris and I get Oops, try again! Did you
> create a function called trip_cost? Not really sure why

Your problem is: codecademy is dumb and its errors are, too.

>>> def trip_cost(city, days):
... totalCost = plane_trip_cost(city) + hotel_cost(nights) +
rental_car_cost(days)

There isn’t a “nights” parameter in your function, and you try to use
it for hotel_cost().  Replace it with days.  And perform one of the
variants, ending up with:

def trip_cost(city, days):
return plane_trip_cost(city) + hotel_cost(days) + rental_car_cost(days)

--
Kwpolska  | GPG KEY: 5EAAEA16
stop html mail| always bottom-post
http://asciiribbon.org| http://caliburn.nl/topposting.html
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Codeacademy Problem

2013-04-29 Thread ChrisKwpolskaWarrick
On Mon, Apr 29, 2013 at 5:15 PM, Joseph Parkton  wrote:
> I am working on a codeacademy problem and I am stuck. The instructions are
> as follows:
>
> INSTRUCTIONS
>
> Below your existing code, write a function called trip_cost that takes two
> inputs, city and days. cityshould be the city that you are going to visit
> and days should be the number of days that you are staying.
>
> Have your function return the sum of the rental_car_cost, hotel_cost, and
> plane_ride_cost functions with their respective inputs.
>
>
> my code so far looks like this:
>
> def hotel_cost(nights):
>
> nights = nights * 140
>
> return nights
>
>
>
> def plane_ride_cost(city):
>
> if city == 'Charlotte':
>
> return 183
>
> if city == 'Tampa':
>
> return 220
>
> if city == 'Pittsburgh':
>
> return 222
>
> if city == 'Los Angeles':
>
> return 475
>
>
> def rental_car_cost(days):
>
> dailyCost = 40
>
> dailyCost = dailyCost * days
>
> if days >= 3:
>
> dailyCost = dailyCost - 20
>
> if days >= 7:
>
> dailyCost = dailyCost - 30
>
> return dailyCost
>
>
>
> def trip_cost(city, days):
>
> totalCost = plane_trip_cost(city) + hotel_cost(nights) +
> rental_car_cost(days)
>
> #And here is where I am stuck...
>
>
> It is probably a simple answer but I don't know how to accomplish it. Any
> help is appreciated.
>
>
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>

Two options:
(a) replace `totalCost =` with `return`
-OR-
(b) add `return totalCost` under the equation.

You already used return before, so why didn’t you do it there?  Or was
this code auto-added by codecademy?
--
Kwpolska  | GPG KEY: 5EAAEA16
stop html mail| always bottom-post
http://asciiribbon.org| http://caliburn.nl/topposting.html
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] totalViruses[i] /= float(numTrials),

2013-04-24 Thread ChrisKwpolskaWarrick
On Wed, Apr 24, 2013 at 4:59 PM, Sydney Shall  wrote:
>  I am a beginner just learning Python.
>
> I have come across the following usage for the first time.
>
>   totalViruses[i] /= float(numTrials)
>
> Does it mean? ;  totalViruses[i] = totalViruses[i]/float(numTrials)
> --
> Sydney
>
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>

Yup.  Similar expressions exist for other binary operators (+, -, *, etc.)

--
Kwpolska  | GPG KEY: 5EAAEA16
stop html mail| always bottom-post
http://asciiribbon.org| http://caliburn.nl/topposting.html
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Why do I get an "unvalid syntax" on the print line for number1

2013-04-23 Thread ChrisKwpolskaWarrick
On Sat, Apr 20, 2013 at 10:33 PM, Pat Collins  wrote:
> Any help appreciated.
>
>
> #!/usr/bin/env python
> """
> number.py Demonstrates collecting a number from the user.
> """
>
> number_string1 = float(input("Give me a number: "))
> number1 = (number_string1)
>
> number_string2 = float(input("Give me another number: "))
> number2 = (number_string2)
>
> print number1, "times", number, "+", number1 * number2
>
>
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>

You are probably using Python 3 (check with `python --version`).  In
this version, print is a function.  You need to do the following
instead:

print(number1, "times", number, "+", number1 * number2)

--
Kwpolska  | GPG KEY: 5EAAEA16
stop html mail| always bottom-post
http://asciiribbon.org| http://caliburn.nl/topposting.html
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] string.Template

2013-04-23 Thread ChrisKwpolskaWarrick
On Tue, Apr 23, 2013 at 4:14 PM, Albert-Jan Roskam  wrote:
> Hello,
>
> Is there a better, *built-in* alternative for the code below? The recursion 
> works,
> but it feels like reinventing the wheel.
>
> import string
>
> def translate(template, *args):
> """Recursively $-substitute  using  as a replacement"""
> syntax = string.Template(template).substitute(*args)
> if "$" in syntax:
> return translate(syntax, *args)
> return syntax
>
> template = """\
> Monty $surname
> $more
> """
> more = """\
> The quest for the holy $grail
> """
> surname="Python"
> grail="Grail"
> print translate(template, locals())
>
> Thank you!
>
> Regards,
> Albert-Jan
>
>
> ~~
> All right, but apart from the sanitation, the medicine, education, wine, 
> public order, irrigation, roads, a
> fresh water system, and public health, what have the Romans ever done for us?
> ~~
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor

1. locals() is hacky and you shouldn’t use it.
2. Do you need “$”?  Why not use the newfangled {} syntax (since
Python 2.6)?  Example:
   '2 + 2 = {val}'.format(val='fish')
   Or:
   '2 + 2 = {0}'.format('fish')
   Or even:
   '2 + 2 = {}'.format('fish')
3. I doubt that there is anything better if you want $.

--
Kwpolska  | GPG KEY: 5EAAEA16
stop html mail| always bottom-post
http://asciiribbon.org| http://caliburn.nl/topposting.html
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] change of email

2013-03-31 Thread ChrisKwpolskaWarrick
On Sun, Mar 31, 2013 at 5:31 PM, Dipo Elegbede  wrote:
>
> Hi,
>
> I would like to have my email changed from delegb...@dudupay.com to 
> dipo.elegb...@dipoelegbede.com
> [snip bullshit]
>
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>

Unsubscribe and resubscribe at
http://mail.python.org/mailman/listinfo/tutor — just as the signature
below your mail claims!  BTW, did you perchance produce your mail
address through having a cat sit on your keyboard?

--
Kwpolska  | GPG KEY: 5EAAEA16
stop html mail| always bottom-post
http://asciiribbon.org| http://caliburn.nl/topposting.html
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor