Re: [Tutor] PySide 1.2.2 and Python 3 - "native Qt signal is not callable"

2014-08-31 Thread Juan Christian
I'm changing so much the code that I got lost now.

Code so far: http://pastebin.com/u4xwZuyJ

I'm getting this error. 'value = float(row[-1])' is getting the values OK,
but when I do 'rates[row[0]] = value' it screws things up.

===
Traceback (most recent call last):
  File "C:.../currency.py", line 48, in 
date = get_rates()
  File "C:.../currency.py", line 40, in get_rates
print(rates[row[0]] + " / VALUE : " + str(value))
KeyError: 'U.S. dollar '

Process finished with exit code 1
===


2014-08-30 21:43 GMT-03:00 Danny Yoo :

> Hi Juan,
>
> Wait, you are working with a CSV file, right?  You should not be
> trying to parse this by hand if you can avoid it: there's a 'csv'
> parser library in the Standard Library.
>
> https://docs.python.org/3.1/library/csv.html
>
> So:
>
> 
> import codecs
> import urllib.request
> import csv
>
> urlString = "http://www.bankofcanada.ca/en/markets/csv/exchange_eng.csv";
> rawFile = urllib.request.urlopen(urlString)
> decodedFile = codecs.getreader("utf-8")(rawFile)
> rows = csv.reader(decodedFile)
>
> for row in rows:
> print(repr(row))
> ###
>
>
> should take better advantage of what the Standard Library provides
> you: then you just deal with the records.  You might have to do a
> little to filter out the beginning comment lines, but that shouldn't
> be too bad.
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] PySide 1.2.2 and Python 3 - "native Qt signal is not callable"

2014-08-31 Thread Juan Christian
Let's see, the print is just "debug", it's not necessary in the program.

'row[0]' is the first element of the current row. Ex.: row = ['a', 'b',
'c', 'd'] - row[0] would be 'a'

'rates' is a dictionary, 'rates[row[0]]' would update the key row[0] in the
dict with the 'value'

I think that's it, right?


2014-08-30 22:37 GMT-03:00 Danny Yoo :

> As the error message suggests, the problem might be near line 40.
>
>
> Look at lines 40 and 41 in your program.
>
> print(rates[row[0]] + " / VALUE : " + str(value))
> rates[row[0]] = value
>
> Look at it very carefully, and try to explain to yourself what those
> two lines mean.
>
> What do you _want_ to happen when those two statements execute?
>
> What does "row[0]" mean?
>
> What does "rates[row[0]]" mean?
>
> Do you notice something strange?
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] PySide 1.2.2 and Python 3 - "native Qt signal is not callable"

2014-08-31 Thread Juan Christian
Yes, the print, as I said, is DEBUG only.

The way you said works: http://pastebin.com/bqCjNZGH
Code: http://pastebin.com/9u2WCVat

Everything seems to be working, but, when I try to really use the program
and convert something change the spinBox value I get:


###
Traceback (most recent call last):
  File "C:/.../currency.py", line 20, in update_ui
amount = (rates[from_] / rates[to]) * fromSpinBox.value()
TypeError: list indices must be integers, not str
###

What I have here is a DICT, not a LIST, why Python is reading it as a list?
I do need to pass a str (the currency names) to get the values from the
dict. I'm reading the doc trying to figure this out.


2014-08-30 23:58 GMT-03:00 Danny Yoo :

> On Sat, Aug 30, 2014 at 7:49 PM, Juan Christian
>  wrote:
> > Let's see, the print is just "debug", it's not necessary in the program.
> >
> > 'row[0]' is the first element of the current row. Ex.: row = ['a', 'b',
> 'c',
> > 'd'] - row[0] would be 'a'
> >
> > 'rates' is a dictionary, 'rates[row[0]]' would update the key row[0] in
> the
> > dict with the 'value'
> >
> > I think that's it, right?
>
>
> Close enough.  Let's look again now.
>
>  print(rates[row[0]] + " / VALUE : " + str(value))
>  rates[row[0]] = value
>
> The print statement here is trying to print the value for a record
> that hasn't been entered in yet.  So one way to naively fix this is to
> just switch the statements around:
>
> rates[row[0]] = value
> print(rates[row[0]] + " / VALUE : " + str(value))
>
> But that probably doesn't mean what you want.  Otherwise, you'd be
> printing the value _twice_ in your debugging output.  Try it out and
> you'll see what I mean.
>
> You probably meant to write:
>
>  print(row[0] + " / VALUE : " + str(value))
>  rates[row[0]] = value
>
> This is why human understanding is necessary here: it's all too easy
> to make a program run, but not make much sense.  Here, there are at
> least two ways to "fix" the erroneous situation, but only you can tell
> us the right thing to do is.
>
> That's why I asked very emphatically: what do you mean?  :P
>
>
> (And frankly, you probably don't want the print statement there in the
> first place: it's debugging output.  Right?)
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] PySide 1.2.2 and Python 3 - "native Qt signal is not callable"

2014-08-31 Thread Juan Christian
Thank you my friend!

It was line 48. The 'sorted()' method transformed my dict in a list. I do
need this approach to put the keys in a sorted way, but know I do it
directly, like 'fromComboBox.addItems(sorted(rates.keys()))' and
'toComboBox.addItems(sorted(rates.keys()))', so that I don't overwrite my
dict.

Final code working: http://pastebin.com/9vK1YBfA

3 USD to BRL from Google: 6.71
3 USD to BRL from my App: 6.71

3.50 Euro to YEN from Google: 478.50
3.50 Euro to YEN from my App: 478.67

Close enough, since it's a learning software, I don't need precise
conversions, and it's not my fault, it's Bank Of Canada fault =p their CSV
is a bit outdated.

Thanks for the patience and not posting "take this code, it works", your
way is much more helpful.


2014-08-31 0:27 GMT-03:00 Danny Yoo :

> >
> > Everything seems to be working, but, when I try to really use the program
> > and convert something change the spinBox value I get:
> >
> >
> > ###
> > Traceback (most recent call last):
> >   File "C:/.../currency.py", line 20, in update_ui
> > amount = (rates[from_] / rates[to]) * fromSpinBox.value()
> > TypeError: list indices must be integers, not str
> > ###
> >
> > What I have here is a DICT, not a LIST, why Python is reading it as a
> list?
> > I do need to pass a str (the currency names) to get the values from the
> > dict. I'm reading the doc trying to figure this out.
>
>
>
> What statements affect the value of rates?  Do a text search if you
> have to.  Search for anything that looks like "rates = "...
>
> Believe the error message unless something very unusual is happening.
> Usually, Python is telling you the truth.   You _know_ you were
> dealing with a dictionary earlier.  And yet, you also know, from the
> error message, that something has changed "rates" from a dictionary to
> a list.
>
> What statements in the program could have provoked this?  I see at
> least one in your program that probably will do it.  I have no idea
> what that particular statement is trying to do.
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Interacting with stderr

2014-08-31 Thread Crush
Alan said, 

"... you are reassigning p in the middle of a loop that 
depends on p. That's usually not a good idea..."

If not what I changed my code to, then I reckon I do not understand what he is 
suggesting I do. 

I have to reparse stderr, each time test_loop.sh is executed the content of 
stderr is different i.e. frames, bitrate, time running, etc. Picture, stderr 
out is being printed to the screen as a running log while the machine is 
decoding. The frames, time, etc. are counting up. If it has been decoding for 3 
days, the the frames, time, etc. will reflect this. 

As far as killing off every avconv and bmdplay process, that is exactly what I 
need to do if they exist before I execute test_loop. I need a "clean slate" 
so-to-speak before each execution. 

Again, my code works so far in the lab, but I havent tested it with a live 
broadcast yet. I figured it would not work the same while testing live and I 
was anticipating changes would need to be made like what you suggested...

"This function won't work as you intend. Specificly, the "if" test is wrong. 
You want to change:
if proc.name == process1 and process2:
if proc.name in (process1, process2):"

Psutil.Popen works just fine. And I will remove "out, err = p.communicate()" as 
you are are correct, it is not being used. 

Yes the rest of my code does in fact work fine. Would you be willing to 
Teamviewer into my machine, so you can see a healthy decoding? This would give 
you a better understanding of what I am trying to accomplish. 

Thank you, 

Bo

>> On Aug 31, 2014, at 1:22 AM, Cameron Simpson  wrote:
>> 
>> On 30Aug2014 22:32, Crush  wrote:
>> Thank you Allan for your criticism. Please see the below changes. As far as 
>> the embedded loops, I know no other way to achieve the same out come.
> 
> Regrettably I've lost Alan's email on that (I had it:-).
> 
> It looks like you've taken he concern over nested use of p.stderr too 
> literally. It loops like you avoid using the same stderr by restarting 
> "test_loop.sh" in the inner loops and reparsing their error outputs. I'm 
> fairly sure that is not what Alan intended and also not what you want to be 
> doing.  Please explain your thinking here.
> 
> Regarding nested loops on the same iterable:
> 
> It is ok to nested use of an iterator, with some caution. The typical use 
> case is some sort of nesting parse of the output. For example, if you were 
> looking for the word "Segmentation", and then intending to act specially on 
> all following lines until some marker. Another gleaming example that springs 
> to mind would be gathering up python stack traces (multiline outputs) in some 
> error log.
> 
> You'd fairly naturally end up with code a bit like this:
> 
> for line in p.stderr:
>   if "Segemntation" in line:
> # ok, found the start line
> for inner_line in p.stderr:
>   if "end segemntation marker" in inner_line:
> break
>   ... do something with inner_line
> 
> That essentially has the effect that all the lines from "Segmentation" to 
> "end segemntation marker" are processed specially by the inner loop, and 
> after you see the end marker you return to the outer loop, looking for the 
> next occurence of "Segmentation".
> 
> There is really only one pitfall with this, and that is the possibility that 
> the end marker line is itself important.
> 
> Imagine you had two inner loops, one for the "Segmentation" section and 
> another to handle some other section, like this:
> 
> for line in p.stderr:
>   if "Segemntation" in line:
> # ok, found the start line
> ... do the "Segmentation" section ...
>   elif "other-section" in line:
> # ok, found the start line
> ... do the "other-section" section ...
>   else:
> # boring line, report it or discard it etc
> 
> Simple and straight forward, yes? It will nicely handly input like this:
> 
>  blah
>  blah
>  begin Segmentation
>>> stuff
>>> more stuff
>  end segmentation marker
>  blah
>  blah
>  begin other-section
>>> other stuff
>>> even more other stuff
>  end the other section
>  blah
> 
> However, consider the case where the end marker for the "Segmentation" 
> section is not some special line generated by the "Segmentation" event, but 
> simply some line that is not a match. Like the beginning of an 
> "other-section" section. Eg:
> 
>  blah
>  blah
>  begin Segmentation
>>> stuff
>>> more stuff
>  begin other-section
>>> other stuff
>>> even more other stuff
>  blah
> 
> With input like that, the "end of section" line is itself an important line 
> that needs to be considered. But the loop as written "consumes" the marker 
> line, and it is not available for recognition on the next outer loop pass 
> (because that fetches the next line).
> 
> This is where nested loops on the same iterable can have an issue. There are 
> several things you can do about it depending on your code and your 
> preferences.  
>> def kill_proc(process1, process2):
>> i = psutil.Popen(["ps", "cax"], stdout=PI

Re: [Tutor] Interacting with stderr

2014-08-31 Thread Alan Gauld

On 31/08/14 14:25, Crush wrote:

Alan said,

"... you are reassigning p in the middle of a loop that
depends on p. That's usually not a good idea..."

If not what I changed my code to, then I reckon I do not

> understand what he is suggesting I do.

Your original code looked like this:

p = subprocess()
for line in p.stderr:
if some condition:
   p = subprocess()   # now reassigned p to a new subprocess
   for line in p.stderr:
   do stuff

So the question is:
What happens to the outer loop when you finish 'do stuff'?

It may be that it is doing what you want, or it may be that
you want to break the outer loop when your some condition
succeeds. I'm not sure?

If you do want to exit the outer loop a more explicit
way would be to set a flag and break:

p = subprocess()
for line in p.stderr:
if some condition:
   some_flag = True
   break
elif other condition:
   other_flag = True
   break

if some_flag:
p = subprocess()
for line in p.stderr:
do stuff
elif other_flag:
do other stuff

But I haven't read through the code in enough detail to be
sure what you are doing, it was just a general observation
that resetting the the thing that your loop depends on
is usually a bad idea. A bit like cutting off the branch
of the tree that you are standing on...

--
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


Re: [Tutor] reading strings and calculating totals

2014-08-31 Thread Alex Kleider

On 2014-08-30 13:13, Alan Gauld wrote:


BUT, there is a much better way using Pythons for loop:

total = 0
for line in infile:
total += float(line)

That automatically reads all the lines ion the file so
you don't need to check for empty lines, set up the
first line etc.


 infile.close()


And if you use Pythons 'with' structure you don't
need the close either, so your whole becomes

total = 0
with open('/Users/richarddillon/Desktop/numbers.txt', 'r') as infile:
for line in infile:
total += float(line)
print(total)

Which is shorter, safer, and more readable.

HTH


..but isn't there a problem if the file contains empty lines?


float("\n")

Traceback (most recent call last):
  File "", line 1, in 
ValueError: could not convert string to float:

float('')

Traceback (most recent call last):
  File "", line 1, in 
ValueError: could not convert string to float:



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


[Tutor] calculate percents of items in a list

2014-08-31 Thread LN A-go-go


What would be a better way to calculate percentages of items in a list?
please

CountList = [9221382, 10374466, 5192905, 1710238, 3359]
CL = [float(i) for i in CountList]
CL
sum = CL[0] + CL[1] + CL[2] + CL[3] + CL[4]
import math
perList = []
n = 0
def percentage(CL,sum):
 for i in CL:
 PER = "return 100 * float (CL[0])/float (sum)"
 perList.append(PER)
 n = n + 1___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


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

2014-08-31 Thread Richard Dillon
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

Here's the code:

#   Richard Dillon

#   This program reads data from a .txt file and calculates a total
#   data in text file: 1,2,3,4 and 5 for a total of 15
#   error message: Non-numeric data found in the file

def main():


total = 0.0

try:

infile = open('/Users/richarddillon/Desktop/numbers.txt', 'r')

for line in infile:
amount = float(line)
total += amount

infile.close()

print(format(total, ',.2f'))

except IOError:
print('An error occured trying to read the file.')

except ValueError:
print('Non-numeric data found in the file.')

except:
print('An error occured.')

main()
___
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 Chris “Kwpolska” Warrick
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 
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 Steven D'Aprano
On Sun, Aug 31, 2014 at 09:31:25AM -0700, Richard Dillon wrote:

> My text file has five numbers, 1-5
> I don't what the problem is.

You'll probably find out if you ask Python to show you what is actually 
causing the problem.


> I've written the file using Word (saved as .txt ) as well as TextEdit
> Python 3.4.1 on a Mac
> 
> Here's the code:
> 
> #   Richard Dillon
> 
> #   This program reads data from a .txt file and calculates a total
> #   data in text file: 1,2,3,4 and 5 for a total of 15
> #   error message: Non-numeric data found in the file
> 
> def main():
> total = 0.0
> try:
> infile = open('/Users/richarddillon/Desktop/numbers.txt', 'r')
> for line in infile:
> amount = float(line)
> total += amount
> infile.close()
> print(format(total, ',.2f'))
> except IOError:
> print('An error occured trying to read the file.')

You don't know that it is a read error. Look at the try block: you do 
SEVEN different things:

- open a file
- read the file
- convert lines of text into floats
- add numbers together
- close the file
- call the format function
- print some string.

All of them could *in principle* raise IOError, although in practice 
only three of them are serious candidates. If you have an IOError, how 
do you know whether it was *opening*, *reading* or *closing* the file 
that failed?

(Yes, closing files can fail.)

Lesson 1: never protect too much by a single try...except block.

Lesson 2: never catch any error that you don't know how to recover from. 
If you *don't* catch the IOError, Python will print the full exception, 
which will show you exactly what failed (say, opening the file), the 
error code, and the error message.

 
> except ValueError:
> print('Non-numeric data found in the file.')

Again, there are seven things which could theoretically raise 
ValueError, although this time only one of them is likely to. Never the 
less, the same rule applies: don't protect too much with a try block. In 
this case, this is much more useful:


infile = open('/Users/richarddillon/Desktop/numbers.txt', 'r')
for line in infile:
try:
amount = float(line)
except ValueError:
print(repr(line))
raise
total += amount
infile.close()
print(format(total, ',.2f'))


The call to repr will convert any weird invisible characters to 
backslash escapes so you can see them. But I suspect what you will see 
is nothing weirder than a blank line:

py> line = '\n'  # blank line
py> float(line)
Traceback (most recent call last):
  File "", line 1, in 
ValueError: could not convert string to float:


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

Oh, well that explains everything. "An error occurred." With all that 
diagnostic information, debugging will be so easy!

Not.

Seriously, don't do that. If an error occurs, Python gives you a heap of 
information to make it easy to debug. You collect that information, 
flush it down the toilet, and replace it with an innane and meaningless 
generic message like "An error occurred".


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


Re: [Tutor] calculate percents of items in a list

2014-08-31 Thread Danny Yoo
On Aug 31, 2014 11:34 AM, "LN A-go-go" 
wrote:
>
>
> What would be a better way to calculate percentages of items in a list?
> please
>

Without showing us your code, try to explain a few examples of the problem
you're trying to solve, and show us expected answer. The problem of just
showing code is that it may work perfectly well, and yet do things that you
do not want.

Concretely, I have no idea what you mean by the term "calculate percentage
of items in a list".  You need to explain the idea in terms that are
independent of your code.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


[Tutor] how import a module upon instantiation of a class?

2014-08-31 Thread Albert-Jan Roskam
Hi,

I want to import a module upon instantiation (not definition) of a class. What 
is the best way to do this? In my case, I need the "icu" module in only one 
place/class of the program. If that class won't be used, I don't want to have 
an ImportError. Also, it might be nice to do the imports only when you actually 
need that functionality. It's probably not really PEP-compliant to put the 
imports somewhere else than at the top of the module, but I can live with that.


import some_nonbuiltin  # I don't want it here!


class KlassA(object):
import some_nonbuiltin  # nope

def __init__(self):
some_nonbuiltin = __import__("some_nonbuiltin") # idem

x = some_nonbuiltin.blah()


class KlassB(object):
"""some_nonbuiltin not needed here! """

def __init__(self):
pass

 
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:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] reading strings and calculating totals

2014-08-31 Thread Alan Gauld

On 31/08/14 19:32, Alex Kleider wrote:


total = 0
with open('/Users/richarddillon/Desktop/numbers.txt', 'r') as infile:
for line in infile:
total += float(line)
print(total)


..but isn't there a problem if the file contains empty lines?


Yes you are right. And my second reply did point out that
the OP would need to add some lines to catch any such
non-conformities in his data.

--
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


Re: [Tutor] how import a module upon instantiation of a class?

2014-08-31 Thread Peter Otten
Albert-Jan Roskam wrote:

> I want to import a module upon instantiation (not definition) of a class.
> What is the best way to do this? In my case, I need the "icu" module in
> only one place/class of the program. If that class won't be used, I don't
> want to have an ImportError. Also, it might be nice to do the imports only
> when you actually need that functionality. It's probably not really
> PEP-compliant to put the imports somewhere else than at the top of the
> module, but I can live with that.
> 
> 
> import some_nonbuiltin  # I don't want it here!
> 
> 
> class KlassA(object):
> import some_nonbuiltin  # nope
> 
> def __init__(self):
  global some_nonbuiltin
  import some_nonbuiltin

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


Re: [Tutor] calculate percents of items in a list

2014-08-31 Thread Dave Angel
LN A-go-go  Wrote in message:
> 

Please post in text mode. It's a real pain trying to respond to
 the memory of your post.


sum () is a built-in function that will add all the floats in CL.
 Of course you can't use it after you've overloaded it with a new
 meaning. 

In your loop, you refer to CL [0] when you probably mean i. 

You also increment some variable in that loop when you're not using it.

Next you have a complicated expression that calls float () twice
 on values that are already floats.

As you've already been told, it'd be nice to show us the result
 you got, and the result you expected. 

-- 
DaveA

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


[Tutor] Good Text Editor/IDE for Python

2014-08-31 Thread Juan Christian
I've been using PyCharm to code in Python but it seems a bit "overpowered"
for this task, and there are some annoying bugs. I used Sublime Text 2 in
the past, but it seems to be dead now (last update was JUN/2013), so I
don't really know any good options.

What do you guys use to code?
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Good Text Editor/IDE for Python

2014-08-31 Thread Steven D'Aprano
On Sun, Aug 31, 2014 at 09:12:24PM -0300, Juan Christian wrote:
> I've been using PyCharm to code in Python but it seems a bit "overpowered"
> for this task, and there are some annoying bugs. I used Sublime Text 2 in
> the past, but it seems to be dead now (last update was JUN/2013), so I
> don't really know any good options.
> 
> What do you guys use to code?

I wouldn't be too concerned about the lack of updates to Sublime. 
Perhaps there are no updates because there are no bugs to fix, code to 
remove, or requested features to add. If it works, it works.

You don't say what operating system you're using. I use Linux, and as 
far as I am concerned, the best IDE for Linux is Linux itself:

http://blog.sanctum.geek.nz/series/unix-as-ide/
http://michaelochurch.wordpress.com/2013/01/09/ide-culture-vs-unix-philosophy/

My IDE is:

- A good programmer's editor, ideally one that supports a tabbed
  interface. I normally use kate (from KDE 3, not KDE 4) or geany, or
  at a pinch kwrite although it's not tabbed.

- A web browser, for looking up documentation and doing web searches.

- A good tabbed terminal application. Konsole from KDE is my 
  preferred choice, but just about any one will do.

In the terminal, I'll open anything up to half a dozen tabs. One for 
running source control (git or hg) and other utilities, another for 
running the application I'm writing and performing tests, and at least 
one interactive Python session for trying out small snippets and looking 
up interactive help.

Just recently, I've customised my interactive Python with a powerful set 
of tab completion commands, similar to that provided by IPython. While 
typing, if I hit tab, it will try to complete the current variable, 
function, module or file name. I don't know how I programmed without it 
all these years :-)



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


Re: [Tutor] calculate percents of items in a list

2014-08-31 Thread Steven D'Aprano
On Sun, Aug 31, 2014 at 07:31:13PM -0400, Dave Angel wrote:
> LN A-go-go  Wrote in message:
> > 
> 
> Please post in text mode. It's a real pain trying to respond to
>  the memory of your post.

LN did post in text mode. Perhaps your email or news client is unable to 
deal with standard multipart/alternative attachments? If that's the 
case, I sympathise with your pain, but it's 2014 not 1994 and you ought 
to stop blaming the poster for your poor tools. Any email client which 
cannot reply to and quote from the text/plain part of a multipart 
message is too crappy for words. That's basic functionality.

If you absolutely cannot or will not upgrade to a proper client, have 
you considered copying the original text before replying, pasting it 
into your reply, and manually adding quote markers?


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


Re: [Tutor] calculate percents of items in a list

2014-08-31 Thread Steven D'Aprano
Hello,

You seem to have deliberately set the Reply-To header for replies to go 
back to you, instead of allowing them to go to the mailing list for 
others to take part in the conversation. I don't know if that was you 
personally, or just another sign of the major suckage that is Yahoo 
mail, but either way I have honoured that request this time, but 
normally replies to questions on the tutor mailing list should go to 
the mailing list so that the others may learn.

More comments below, interleaved with your questions.


On Sun, Aug 31, 2014 at 10:28:32AM -0700, LN A-go-go wrote:
> 
> 
> What would be a better way to calculate percentages of items in a list?
> please
> 
> CountList = [9221382, 10374466, 5192905, 1710238, 3359]
> CL = [float(i) for i in CountList]

I really don't know why you convert the numbers into floats. There 
doesn't seem to be any reason for that -- you can sum integer numbers 
just as easily. If you insist on floats, why not just make them floats 
in the first place?

CountList = [9221382.0, 10374466.0, 5192905.0, 1710238.0, 3359.0]

but that's silly. If they are meant to be *counts*, then you cannot have 
a fraction of a count. Just keep them as ints.

> CL
> sum = CL[0] + CL[1] + CL[2] + CL[3] + CL[4]

Here you accidentally "shadow" the built-in sum() function. You 
shouldn't do this unless you know what you are doing. Instead:

total = sum(CountList)

gives you the total you are after.


> import math

That's not used or needed.


> perList = []
> n = 0
> def percentage(CL,sum):
>  for i in CL:
>  PER = "return 100 * float (CL[0])/float (sum)"
>  perList.append(PER)
>  n = n + 1

You appear to be wanting to calculate cumulative percentages. A simple 
example:

CountList = [5, 2, 8, 5]
total = 20
cumulative percentages = [25.0, 35.0, 75.0, 100.0]

Is that correct? If so, this will do it:

counts = [9221382, 10374466, 5192905, 1710238, 3359]
cumulative_totals = []
last = 0
for value in counts:
last += value
cumulative_totals.append(last)

total = sum(counts)
# check that the last value matches the total:
assert total == cumulative_totals[-1]  
cumulative_percentages = []
for value in cumulative_totals:
perc = value*100.0/total
cumulative_percentages.append(perc)

print(cumulative_percentages)

I think that should do the trick.


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


Re: [Tutor] Good Text Editor/IDE for Python

2014-08-31 Thread Juan Christian
I'm using Windows, but I do use Linux on a daily basis.

On Sunday, August 31, 2014, Steven D'Aprano  wrote:

> On Sun, Aug 31, 2014 at 09:12:24PM -0300, Juan Christian wrote:
> > I've been using PyCharm to code in Python but it seems a bit
> "overpowered"
> > for this task, and there are some annoying bugs. I used Sublime Text 2 in
> > the past, but it seems to be dead now (last update was JUN/2013), so I
> > don't really know any good options.
> >
> > What do you guys use to code?
>
> I wouldn't be too concerned about the lack of updates to Sublime.
> Perhaps there are no updates because there are no bugs to fix, code to
> remove, or requested features to add. If it works, it works.
>
> You don't say what operating system you're using. I use Linux, and as
> far as I am concerned, the best IDE for Linux is Linux itself:
>
> http://blog.sanctum.geek.nz/series/unix-as-ide/
>
> http://michaelochurch.wordpress.com/2013/01/09/ide-culture-vs-unix-philosophy/
>
> My IDE is:
>
> - A good programmer's editor, ideally one that supports a tabbed
>   interface. I normally use kate (from KDE 3, not KDE 4) or geany, or
>   at a pinch kwrite although it's not tabbed.
>
> - A web browser, for looking up documentation and doing web searches.
>
> - A good tabbed terminal application. Konsole from KDE is my
>   preferred choice, but just about any one will do.
>
> In the terminal, I'll open anything up to half a dozen tabs. One for
> running source control (git or hg) and other utilities, another for
> running the application I'm writing and performing tests, and at least
> one interactive Python session for trying out small snippets and looking
> up interactive help.
>
> Just recently, I've customised my interactive Python with a powerful set
> of tab completion commands, similar to that provided by IPython. While
> typing, if I hit tab, it will try to complete the current variable,
> function, module or file name. I don't know how I programmed without it
> all these years :-)
>
>
>
> --
> Steven
> ___
> 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


Re: [Tutor] Good Text Editor/IDE for Python

2014-08-31 Thread Cameron Simpson

On 01Sep2014 11:13, Steven D'Aprano  wrote:

On Sun, Aug 31, 2014 at 09:12:24PM -0300, Juan Christian wrote:

I've been using PyCharm to code in Python but it seems a bit "overpowered"
for this task, and there are some annoying bugs. I used Sublime Text 2 in
the past, but it seems to be dead now (last update was JUN/2013), so I
don't really know any good options.

What do you guys use to code?

[...]

You don't say what operating system you're using. I use Linux, and as
far as I am concerned, the best IDE for Linux is Linux itself: [...]

http://blog.sanctum.geek.nz/series/unix-as-ide/
http://michaelochurch.wordpress.com/2013/01/09/ide-culture-vs-unix-philosophy/


I'm mostly on OSX, but of course that is a UNIX platform as well:-) So my IDE 
is somewhat like Steven's. BTW, there are many many discussions in the 
python-list archives on the various development environments people use.



My IDE is:

- A good programmer's editor, ideally one that supports a tabbed
 interface. I normally use kate (from KDE 3, not KDE 4) or geany, or
 at a pinch kwrite although it's not tabbed.


I'm a vim user, and use it for everything (email, programming, any other plain 
text editing). I've been using vi since, um, maybe 1985, and my fingers know 
it. Of course, I use emacs editing keystrokes (a very limited subset of it, 
anyway) in interactive shells, including the Python interactive prompt; it is 
better in that scenario for me because it is modeless - vi is modal, which I 
find a win for coding.


I don't use tabs or subwindows/panes in the editor. I do use tabs in the 
terminal (and my editor runs in a pane in my terminal).



- A web browser, for looking up documentation and doing web searches.


Me too. And I find it very useful to have local copies of the Python doco on my 
desktop; accessing a local copy is really fast and also works when offline. I 
keep a local copy of the latest Python 2 and Python 3 doco to hand. This does 
rely on the doco having a good page size choice; I like a "page" to be a 
chapter. The Python doco does this well, a "page" per module. By contrast, the 
PostgreSQL doco is extremely finely sliced and very irritating to browse.


I use tabs heavily in the web browser.


- A good tabbed terminal application. Konsole from KDE is my
 preferred choice, but just about any one will do.


On OSX the winning choice is iTerm2; I use it exclusively. Tabs and also 
subpanes. It has many good features.



In the terminal, I'll open anything up to half a dozen tabs. One for
running source control (git or hg) and other utilities, another for
running the application I'm writing and performing tests, and at least
one interactive Python session for trying out small snippets and looking
up interactive help.


I use a tab per dev environment. (So a tab for my main project, and I use 
another tab for whichever of its branches I'm working in.)


Within each tab I usually split the tab into 3 vertical panes: an editor in the 
middle )terminal running vim, for me) and a shell on either side. I open python 
interactive prompts at need as opposed to Steven's always-open instance. On 
occasions I split the vertical panes horizontally when I need an extra terminal 
for something short term.



Just recently, I've customised my interactive Python with a powerful set
of tab completion commands, similar to that provided by IPython. While
typing, if I hit tab, it will try to complete the current variable,
function, module or file name. I don't know how I programmed without it
all these years :-)


I must try that sometime.

Cheers,
Cameron Simpson 

Baldrick: Sir, what shall we do if we stand on a mine?
Edmund: Well, Baldrick - I think the common practice is to jump several metres
into the air, and scatter yourself in a wide radius on the way down.
- _Blackadder_
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Good Text Editor/IDE for Python

2014-08-31 Thread Ben Finney
Juan Christian  writes:

> What [text editor] do you guys use to code?

I use GNU Emacs primarily, and sometimes Vim.

My recommendations have been posted in a different forum; I'll repeat
them here.


You can write Python code using any text editor.

You will do well to use a text editor which is deliberately designed for
programming and other related editing tasks.

I would also recommend that a programmer's text editor should:

* Be licensed as free software — the tool should be able to be improved
  and maintained and distributed to you by any party sufficiently
  motivated, not locked up by any single party.

* Work the same on all major platforms — you should not need to abandon
  a tool you like merely because you switch to a different machine for a
  while.

* Be mature with a strong track record — a text editor which has been
  around for some decades, and still has a large following, has
  demonstrated it can survive many different trends in programming
  tools.

* Have good support provided by its own vibrant community — you don't
  necessarily need to join such a community, but you will greatly
  benefit from the fact that a tool has robust community support. That
  the tool is free software is a significant contributor to this.

* Be indefinitely customisable to meet new needs — this ensures that
  anyone sufficiently motivated can allow you to use the tool you
  already know for new tasks that come along. Having a strong community
  of support will mean that most tasks are already supported in the tool
  by people who came before you.

* Properly support many programming languages and related formats — this
  is an outcome of the tool being community-supported, mature, and
  highly customisable. The tool should, in its standard installation,
  already support major programming languages and formats, and have a
  simple way to add supporting plug-ins as you need them.

I know of two obvious text editors that meet these criteria:

* Vim http://www.vim.org/>
  https://en.wikipedia.org/wiki/Vim_%28text_editor%29>

* Emacs https://www.gnu.org/software/emacs/>
  https://en.wikipedia.org/wiki/Emacs>

If you're using a *nix style operating system such as GNU+Linux, you
will have both of these available for installation from the operating
system. On other desktop operating systems you can install them easily
too.

I hope that helps. Familiarising yourself with a strong, free-software,
cross-platform text editor is an essential investment in programming.
Good hunting!

-- 
 \  “Faith is generally nothing more than the permission religious |
  `\ people give to one another to believe things strongly without |
_o__)  evidence.” —Sam Harris, _Letter to a Christian Nation_ 2006 |
Ben Finney

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


Re: [Tutor] Good Text Editor/IDE for Python

2014-08-31 Thread Derek Jenkins
Juan,

Besides Kwrite, I actually use the tools that the others mentioned so
far, although I don't use Emacs often at all (perhaps I have just not
found an advantageous use for it yet). So no real added info here, but
I will say that I've not personally ran into any problems with
Sublime.

For Windows, if you must continue to use it, I can venture to suggest
you give Notepad++ a whirl for a text editor. I have used it on a
handful of occasions and it _generally_ seemed okay enough to keep it
in mind for a rainy day, such as right now. As for PyCharm, I have 0
experience with that so I can't offer any suggestions.



On Sun, Aug 31, 2014 at 9:57 PM, Cameron Simpson  wrote:
> On 01Sep2014 11:13, Steven D'Aprano  wrote:
>>
>> On Sun, Aug 31, 2014 at 09:12:24PM -0300, Juan Christian wrote:
>>>
>>> I've been using PyCharm to code in Python but it seems a bit
>>> "overpowered"
>>> for this task, and there are some annoying bugs. I used Sublime Text 2 in
>>> the past, but it seems to be dead now (last update was JUN/2013), so I
>>> don't really know any good options.
>>>
>>> What do you guys use to code?
>
> [...]
>>
>> You don't say what operating system you're using. I use Linux, and as
>> far as I am concerned, the best IDE for Linux is Linux itself: [...]
>>
>> http://blog.sanctum.geek.nz/series/unix-as-ide/
>>
>> http://michaelochurch.wordpress.com/2013/01/09/ide-culture-vs-unix-philosophy/
>
>
> I'm mostly on OSX, but of course that is a UNIX platform as well:-) So my
> IDE is somewhat like Steven's. BTW, there are many many discussions in the
> python-list archives on the various development environments people use.
>
>
>> My IDE is:
>>
>> - A good programmer's editor, ideally one that supports a tabbed
>>  interface. I normally use kate (from KDE 3, not KDE 4) or geany, or
>>  at a pinch kwrite although it's not tabbed.
>
>
> I'm a vim user, and use it for everything (email, programming, any other
> plain text editing). I've been using vi since, um, maybe 1985, and my
> fingers know it. Of course, I use emacs editing keystrokes (a very limited
> subset of it, anyway) in interactive shells, including the Python
> interactive prompt; it is better in that scenario for me because it is
> modeless - vi is modal, which I find a win for coding.
>
> I don't use tabs or subwindows/panes in the editor. I do use tabs in the
> terminal (and my editor runs in a pane in my terminal).
>
>
>> - A web browser, for looking up documentation and doing web searches.
>
>
> Me too. And I find it very useful to have local copies of the Python doco on
> my desktop; accessing a local copy is really fast and also works when
> offline. I keep a local copy of the latest Python 2 and Python 3 doco to
> hand. This does rely on the doco having a good page size choice; I like a
> "page" to be a chapter. The Python doco does this well, a "page" per module.
> By contrast, the PostgreSQL doco is extremely finely sliced and very
> irritating to browse.
>
> I use tabs heavily in the web browser.
>
>
>> - A good tabbed terminal application. Konsole from KDE is my
>>  preferred choice, but just about any one will do.
>
>
> On OSX the winning choice is iTerm2; I use it exclusively. Tabs and also
> subpanes. It has many good features.
>
>
>> In the terminal, I'll open anything up to half a dozen tabs. One for
>> running source control (git or hg) and other utilities, another for
>> running the application I'm writing and performing tests, and at least
>> one interactive Python session for trying out small snippets and looking
>> up interactive help.
>
>
> I use a tab per dev environment. (So a tab for my main project, and I use
> another tab for whichever of its branches I'm working in.)
>
> Within each tab I usually split the tab into 3 vertical panes: an editor in
> the middle )terminal running vim, for me) and a shell on either side. I open
> python interactive prompts at need as opposed to Steven's always-open
> instance. On occasions I split the vertical panes horizontally when I need
> an extra terminal for something short term.
>
>
>> Just recently, I've customised my interactive Python with a powerful set
>> of tab completion commands, similar to that provided by IPython. While
>> typing, if I hit tab, it will try to complete the current variable,
>> function, module or file name. I don't know how I programmed without it
>> all these years :-)
>
>
> I must try that sometime.
>
> Cheers,
> Cameron Simpson 
>
> Baldrick: Sir, what shall we do if we stand on a mine?
> Edmund: Well, Baldrick - I think the common practice is to jump several
> metres
> into the air, and scatter yourself in a wide radius on the way down.
> - _Blackadder_
>
> ___
> 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

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

2014-08-31 Thread David
On 1 September 2014 02:31, Richard Dillon  wrote:
>
> except IOError:
> print('An error occured trying to read the file.')
>
> except ValueError:
> print('Non-numeric data found in the file.')
>
> except:
> print('An error occured.')

Your other respondents have already said this, but I am going to emphasise it.

The above lines are bad. They do not help you, they only hinder you by
replacing useful information with dumb print statements that tell you
nothing useful. So delete them all!

'except' blocks should only be used when you know why the error
occurred, and they should contain useful extra code to either to
recover from the error or to work around it.

Those dumb print statements are not useful extra code. So delete them.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor