Re: [Tutor] Civil discourse from a newbie's perspective

2012-10-02 Thread Francois Dion
On Mon, Oct 1, 2012 at 9:34 PM, boB Stepp  wrote:
> However, I
> think that extra care may be needed in dealing with newbies who may
> only be taking a programming course using Python because of curriculum
> requirements.

A lot of questions seem to come from college students trying to get
the best grade they can for their assignments and once done with their
Python assignments might never go back to programming. Still, you are
correct in your statement, we are building goodwill for Python and its
community (user groups, forums, lists, conferences, teachers, students
etc) through this list, and it can positively influence people to
stick around (Python and CS) instead of abandoning the field of CS.
Programming with Python is fun! Well, it is supposed to be fun.
Communities for some other programming languages (not naming names)
are known to be very harsh on newcomers, while Python is known to have
a friendly community. We just have to continue mentoring and teaching
with that in mind.

Even worse would be the case of a young aficionado.  It is very hard
to infer the age of a person from a post. As Python is making inroads
in the K-12 sector and through inexpensive computing platforms such as
OLPC, the Raspberry Pi and the like, there is a potential to be
interacting with some very young programmers. I think right now the
bulk of them are sticking to forums (definitely the case with the
Raspberry Pi), but it is inevitable that the makeup of the readership
of this list will change. What will happen when a 9 year old kid who
loves computers is turned away by a cutting remark or heavy criticism?
Similarly, one should be considerate as to the language used.

I'll conclude with King Solomon's proverbial saying: "As apples of
gold in silver carvings is a word spoken at the right time for it"

Thank you kindly,
Francois


--
Francois Dion
solarisdesktop.blogspot.com  -  raspberry-python.blogspot.com
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor



Re: [Tutor] Access HBase

2015-07-14 Thread Francois Dion
On Sat, Jul 11, 2015 at 9:01 AM, Michelle Meiduo Wu 
wrote:

> Hi there,
> I'm just starting to use Python. I'd like to ask which Library is good for
> Python to access HBASE?
>

I think the Python for Data Science group would be a good place to ask:

https://groups.google.com/forum/?fromgroups#!forum/pydata

If you are just starting out in Python, though, I would suggest you learn
core python first.

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


Re: [Tutor] PDF Scrapping

2015-11-25 Thread Francois Dion
This is well beyond the scope of Tutor, but let me mention the following:

The code to pdftables disappeared from github some time back. What is on
sourceforge is old, same with pypi. I wouldn't create a project using
pdftables based on that...

As far as what you are trying to do, it looks like they might have the data
in excel spreadsheets. That is totally trivial to load in pandas. if you
have any choice at all, avoid PDF at all cost to get data. See some detail
of the complexity here:
http://ieg.ifs.tuwien.ac.at/pub/yildiz_iicai_2005.pdf

For your two documents, if you cannot find the data in the excel sheets, I
think the tabula (ruby based application) approach is the best bet.

Francois

On Wed, Nov 25, 2015 at 8:41 AM, Python Beginner <
pythonbeginner...@gmail.com> wrote:

> Oh, I forgot to mention that I am using Python 3.4. Thanks again for your
> help pointing me in the right direction.
>
> ~Chris
>
> On Tue, Nov 24, 2015 at 1:36 PM, Python Beginner <
> pythonbeginner...@gmail.com> wrote:
>
> > Hi,
> >
> > I am looking for the best way to scrape the following PDF's:
> >
> > (1)
> > http://minerals.usgs.gov/minerals/pubs/commodity/gold/mcs-2015-gold.pdf
> > (table on page 1)
> >
> > (2)
> > http://minerals.usgs.gov/minerals/pubs/commodity/gold/myb1-2013-gold.pdf
> > (table 1)
> >
> > I have done a lot of research and have read that pdftables 0.0.4 is an
> > excellent way to scrape tabular data from PDF'S (see
> >
> https://blog.scraperwiki.com/2013/07/pdftables-a-python-library-for-getting-tables-out-of-pdf-files/
> > ).
> >
> > I downloaded pdftables 0.0.4 (see https://pypi.python.org/pypi/pdftables
> ).
> >
> > I am new to Python and having trouble finding good documentation for how
> > to use this library.
> >
> > Has anybody used pdftables before that could help me get started or point
> > me to the ideal library for scrapping the PDF links above? I have read
> that
> > different PDF libraries are used depending on the format of the PDF. What
> > library would be best for the PDF formats above? Knowing this will help
> me
> > get started, then I can write up some code and ask further questions if
> > needed.
> >
> > Thanks in advance for your help!
> >
> > ~Chris
> >
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor
>



-- 
raspberry-python.blogspot.com - www.pyptug.org - www.3DFutureTech.info -
@f_dion
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] To FORMAT or not to

2016-01-03 Thread Francois Dion
The answer is neither. The second shows the intent in part but doesn't
quite get it right.

The intent is to have a string template and insert values in that template:

print("You've visited {} & {}.".format(island, new)

This is totally clear what is going to happen. I'm not relying on the
behaviour of print() to format my string. Format does the formating, print
the printing :)

This separation of concern is a basic building block of good code and is
seen at various scale levels. At a higher level, it is seen in concepts
like MVC.

Another thing you do by having your string separated, is you could have
them defined elsewhere and have, say, a version in english and a version in
french.

I;m sure you can see the value.

Francois

On Sun, Jan 3, 2016 at 7:27 AM, yehudak .  wrote:

> Hi there,
> In a program I wrote the following line (Python 3.5):
>
> print("You've visited", island, '&', new + ".")
>
> A programmer told me that it's a bad habit, and I should have used instead:
>
> print("You've visited {0} {1} {2}{3}".format(island, "&", new, "."))
>
> May I understand why?
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor
>



-- 
raspberry-python.blogspot.com - www.pyptug.org - www.3DFutureTech.info -
@f_dion
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] To FORMAT or not to

2016-01-03 Thread Francois Dion
And as Chris points out, if there is any possibility that the words will be
in a different order in a different language, use {0}, {1} instead of {}.


Francois

On Sun, Jan 3, 2016 at 8:04 AM, Chris Warrick  wrote:

> On 3 January 2016 at 13:27, yehudak .  wrote:
> > Hi there,
> > In a program I wrote the following line (Python 3.5):
> >
> > print("You've visited", island, '&', new + ".")
> >
> > A programmer told me that it's a bad habit, and I should have used
> instead:
> >
> > print("You've visited {0} {1} {2}{3}".format(island, "&", new, "."))
> >
> > May I understand why?
> > ___
> > Tutor maillist  -  Tutor@python.org
> > To unsubscribe or change subscription options:
> > https://mail.python.org/mailman/listinfo/tutor
>
> The programmer was not very intelligent in his use of str.format in
> the first place. A more sensible way to write this is:
>
> print("You've visited {0} & {1}.".format(island, new))
>
> Formatting with constant strings is pointless, just include it in the
> original input. However, string formatting is not.
>
> Here are a couple of reasons:
> * String formatting works everywhere, but this syntax is specific to
> print() — if you use something else, you might end up producing faulty
> code
> * The corrected string formatting usage is more readable than the
> original print()
> * String concatenation with + requires that all arguments are strings,
> which is even less readable
> * With string formatting, you can apply special formatting to your
> inputs (eg. set width, number precision…), which is hard or impossible
> with print()
> * Using print() with commas adds spaces between all entries, which
> might look bad (and it does in this example); the only way to prevent
> that is by setting `sep=`, but then you need to remember about a space
> after "visited" and around the ampersand…
> * Easy to localize (translate into different languages), which is
> generally impossible with any of the other options (some languages
> might rearrange the sentence!)
>
> --
> Chris Warrick 
> PGP: 5EAAEA16
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor
>



-- 
raspberry-python.blogspot.com - www.pyptug.org - www.3DFutureTech.info -
@f_dion
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] python plotting

2016-01-19 Thread Francois Dion
I'm guessing you loaded from pandas import *... It is better to import
pandas as pd, then use pd.read_csv. I also tend to name my data frames df
or a variation and time series as ts.

Speaking of series, If your data is not a series with a datetime type, then
it will be plotted as a categorical, meaning each different X value is
represented at a constant interval, in index order. You need to convert
your time string to a datetime. (pd.to_datetime is your friend).

Francois

On Tue, Jan 19, 2016 at 2:28 PM, Bachir Bachir via Tutor 
wrote:

>  Dear all,
> I have some data taken at specific time of the day and i  want to display
> those data according to the time,attached is the cvs file and the display
> output from python pandas . I used the following script
>  v2=read_csv('v2_12.dat')  #data frame for v2
>  v2.plot(kind='bar', x='Time_hhmmss', y='Av_phase',figsize=(12,1))
> #display for v2 only
> I want to see a gap on the display because there was no data recorded
> between  08:20:56  and   14:55:33  but on my display i see them side by
>  side Is there any way to do  this using python display optionsYour help is
> highly appreciated Thanks much
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor
>



-- 
raspberry-python.blogspot.com - www.pyptug.org - www.3DFutureTech.info -
@f_dion
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Why is the name "self" optional instead of mandatory?

2016-01-21 Thread Francois Dion
On Thu, Jan 21, 2016 at 6:49 AM, Steven D'Aprano 
 wrote:

> On Wed, Jan 20, 2016 at 09:42:29PM -0600, boB Stepp wrote:
>
> > So I really only have one question:  Why not make Python's
> > *traditional* name, "self", mandatory?  Why give the programmer this
> > kind of choice?  [OK, that was two questions.]


[answers ommited]

All great answers. Ben mentioned the four space tab convention as a similar
thing:  Python has a ton of conventions but doesn't enforce them. That is
not the job of the interpreter, at least the Python one, since it has never
enforced any convention.

Yes, individual programmers can enforce these conventions in whichever way
they want. Some see this as a bad thing for coding standards, but that is
easily addressed by tools like pylint. In an enterprise setting, the
pipeline of going from writing code to deploying it will go through a few
phases, including checking for PEP8 compliance, Pylint compliance (the
rules the team cares about), code complexity etc. With pylint, if you try
it on your code with this instead of self, you'll get this in particular:
"Method should have "self" as first argument (no-self-argument)"

Francois


-- 
raspberry-python.blogspot.com - www.pyptug.org - www.3DFutureTech.info -
@f_dion
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Listen for input while performing other tasks

2012-11-25 Thread Francois Dion
On Sun, Nov 25, 2012 at 7:32 AM, Sean Carolan  wrote:
> This is how I'm checking for a button press:

This should really be done with interrupts, but unfortunately there is
no support in the RPi.GPIO module for that, even if you have a patched
kernel.

I've done a workshop earlier this month that was on buttons with
RPi.GPIO, might be of interest:
http://raspberry-python.blogspot.com/2012/11/pyhack-workshop-01.html
http://raspberry-python.blogspot.com/2012/11/piquizmachine.html

(next workshop is on the 8th, but that'll be on the raspberry pi and motors)

Fundamentally, the loop is:

while gpio.input(PIN):
pass
dostuff()

The moment the loop ends, the button was pressed. On the next line you
would do something, and then go back to polling. If you do have to do
something at the same time, you'll have to look into threads. Or you
could launch an external script as a background process.

Now, on to your code:
> modes = (weather, alarmclock, moodlight)
> currmode = 0
> mode = 10  ## mode button is on pin #10

mode and modes are constants. In python, it is a convention to use
caps. MODES= and MODE=
This helps readability of the code. Are weather, alarmclock

Also, I typically import RPi.GPIO as gpio (lowercase). So you would
type gpio.input(MODE). It makes more sense.

> def checkMode():

pass the current mode: def checkmode( current):

> global currmode

That way you dont have to do the above

> modechange = False
> GPIO.setup(mode, GPIO.IN)

Do that outside of the function. gpio.setup() should be done once at
the beginning. It then has plenty of time to stabilise and you are not
wasting time in the function. Also, dont forget to do a gpio.cleanup()
when leaving (and possibly in a try: except: finally: block if it is
likely the program ends abruptly).

> if GPIO.input(mode) == False:
> print "Mode button pressed."
> if currmode < len(modes) - 1:
> currmode += 1
> else:
> currmode = 0
> modechange = True
> #print modes[currmode]
> return (modes[currmode], modechange)
>
> It's pretty simple, really.  If GPIO.input(mode) returns False, then
> the button is pressed.  My function above returns the current mode
> from my modes tuple, and whether a change was detected.

The rest of your code is to support your requirement of returning a
mode and boolean value. It could be a bit tighter, but the main issue
is how you are separating the scope. The loop should be in the
function, and no sleep (or less than 50ms if you insist), else you
might miss the press.

I'm not sure if you were asking for pointers or a complete solution,
so I'll leave it at this for now.

Francois

--
pyptug.blogspot.com  -  raspberry-python.blogspot.com
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] I'm trying to wrap my head around defs

2012-12-04 Thread Francois Dion
On Tue, Dec 4, 2012 at 4:51 PM, frank ernest  wrote:
> Opensuse 12.2 python3.2
> I'm having trouble understanding them.
> Python is my first language...   excluding English.
> I've already read ALL OF THE PYTHON Language Referance and I still don't
> "get it."
> What do they do?

Let's start simple. It is a Python keyword to define a function.

> How do they work?

Just like a function in mathematics, they take some arguments, do
stuff with it (hopefully) and more than likely return something. For
example, cos(angle) defines the cosinus calculation for a given angle.
This function is an object that has been defined at some point by a
def cos(angle):

So there is a difference between *def*ining a function and using it,
hence the def keyword.

> How do you define self?

You do not. It is related to scope,

> The if statement is a statement of comparison. what is a def and more
> specifically a class?

You really need to understand functions first, then scope, then we can
talk class.

So, my question to you before we get too far, are you ok with the
concept of mathematical functions?

Francois

--
www.pyptug.org  -  raspberry-python.blogspot.com
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Get/Set/Attribute Accessors in Python?

2012-12-05 Thread Francois Dion
On Wed, Dec 5, 2012 at 10:38 AM, Malcolm Newsome
 wrote:
> Hey Tutors,
>
> Python is/was my first language.  Yet, I've recently begun learning C# for
> my new job.

My condolences.

> One thing I've come across in C# (and, quite frankly, am having a difficult
> time grasping) is Get and Set (Accessors).
> Since, I don't ever recall reading about this in Python, I'm wondering if
> they exist.  If not, what is the "thinking" behind why they are not included
> in the language?

Nothing prevents you from creating getter and setter methods for all
your values in your class in Python, but really, you don't need to
most of the time. Refactoring and re-engineering your code later on to
use them if you have to, is pretty much transparent to the rest of the
code.

For example:

class Thing:

colorinfo = "#f00:red"

box = Thing()
print(box.colorinfo)


This will print:
#f00:red

You are happy about how short the code is and start using
box.colorinfo all over the place.

later, you decide, you should have used colorinfo as a method (a
getter, ie getcolorinfo() ) instead of a property, because you want to
add arguments to the constructor and use them in the getter. So you
would then have to go and replace every box.colorinfo by
box.colorinfo(), if you were not using python. But since you are, you
end up doing a getter, and keep the property:

class Thing:
def __init__(self,color,name):
self.color = color
self.name = name

def getcolorinfo(self):
return self.color + ':' + self.name

colorinfo = property(getcolorinfo)

box = Thing("#f00","red")
print(box.colorinfo)
box = Thing("#00f","blue")
print(box.colorinfo)

The output of which is
#f00:red
#00f:blue

The key here is that you are now wrapping the string inside a getter
function, where you could do all kinds of other stuff, but yet, you
never had to modify the print line since it still refers to a property
of the box instance of the Thing object. All because of the property
keyword.
Best of both worlds.

Francois

--
www.pyptug.org  -  raspberry-python.blogspot.com
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Trouble importing Paramiko

2012-12-27 Thread Francois Dion
On Thu, Dec 27, 2012 at 8:48 AM, Ufuk Eskici  wrote:
> I got this output with lots of errors:
>   File "build\bdist.win32\egg\paramiko\auth_handler.py", line 311
> except SSHException, e:
>^
> SyntaxError: invalid syntax

Use Python 2.x, Python 3 is in the works, kindoff:

https://github.com/paramiko/paramiko/issues/16
https://github.com/paramiko/paramiko/issues/123

François

--
www.pyptug.org  -  raspberry-python.blogspot.com
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Books for Learning Python

2013-01-11 Thread Francois Dion
On Fri, Jan 11, 2013 at 3:14 PM, Gary L. Gray  wrote:
> On Jan 11, 2013, at 1:39 PM, Alan Gauld  wrote:
> (1) Will Python allow me to create applications that provide a simple GUI 
> interface to something like an integrator for ODEs? Does it have graphics 
> libraries that allow one to animate the motion of simple objects (e.g., 
> spheres, ellipsoids, parallelepipeds, etc.) based on the results of numerical 
> simulations?

Ordinary Differential Equations, I'm assuming.

Python has tons of math / sci libraries. Matplotlib, scipy, pylab etc.
Under Windows, get Python(X,Y) and you will get an IDE, Python, and
all the modules I've mentionned. A quick google, for those coming from
a matlab background:
http://www.christopheralbert.net/2011/03/equivalent-ode-integrators-in-matlab.html

What OS will you be using?

Francois

--
www.pyptug.org  -  raspberry-python.blogspot.com
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] automate add-to-cart with python

2013-01-29 Thread Francois Dion
On Mon, Jan 28, 2013 at 6:32 PM, Alan Gauld  wrote:
> On 28/01/13 22:51, Benjamin Fishbein wrote:
>> In general, despite scouring the Internet, I haven't been able to figure
>> out how to get Python to cause javascripts I find in the html to be run.
>
>
> That's because Javascript is run in the browser which has a Javascript
> interpreter built in. Python doesn't have a Javascript interpreter so can't
> run Javascript.
>
> But that's usually the wrong thing to do anyway so it doesn't matter. What
> you need to do is figure out what the Javascript is doing - usually sending
> some data to a server - and replicate that.
>
> Alternatively fire up a real browser and drive that with automation. How you
> do that will largely depend on the browser and the OS.
>
> Or maybe, just maybe, somebody has written a javascript interpreter in
> Python as a module that you can import. It sounds just about crazy enough
> that it might even exist! But as I said, that's probably the wrong thing to
> do...

The other way around does exists, python in your web browser:
http://brython.info

Did a quick iPhone web app that way and demoed it to our local Python
group last night:
http://raspberry-python.blogspot.com/2013/01/iphone-app-with-python.html

You could easily extend this concept where your python script server
side controls your python script client side through reverse Ajax. And
of course it's also possible to do the whole thing client side,
without a server. Works on all modern browsers too.

François

--
www.pyptug.org  -  raspberry-python.blogspot.com  -  @f_dion
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Python Conference/Tutorial in the USA

2013-06-04 Thread Francois Dion
Where are you situated? You should join a local Python user group. Don
mentionned tripython, which is in North Carolina. There is also PYPTUG [1]
and PyCarolinas [2] 2013 should be announced soon. A little to the
northwest, PyOhio [3] just concluded RFPs and is scheduled for the end of
July. There are similar user groups and conferences around the US. Some
hackerspaces also have Python project nights and workshops. If you tell us
what city you are in, we can point you in the right direction.

Francois

[1] http://www.pyptug.org
[2] http://www.pycarolinas.org/
[3] http://pyohio.org

--
www.pyptug.org  -  raspberry-python.blogspot.com  -  @f_dion


On Tue, Jun 4, 2013 at 2:05 PM, Oladipupo Elegbede <
dipo.elegb...@dipoelegbede.com> wrote:

> Hello,
>
> Kindly let me have details if there are any python conferences/tutorials
> within the USA.
> I just came into the USA.
>
> Thank you all.
>
> Regards.
>
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Future Python

2013-06-05 Thread Francois Dion
You can combine django (or any other framework) with brython, just like you
would with javascript. For example, just this past week, this example was
posted to the brython list:

https://github.com/mrjmad/django_socketio_test

Francois
--
www.pyptug.org  -  raspberry-python.blogspot.com  -  @f_dion


On Wed, Jun 5, 2013 at 7:28 PM, Jim Mooney  wrote:

> On 5 June 2013 13:38, Walter Prins  wrote:
>
>> Jim,
>>
>>
>> You might be interested to know there's several incarnations of Python
>> for browser already available.  PyJS and PyJaco are Python to Javascript
>> compilers, and Brython is basically a Python subset that allows you to
>> write Python and use it as a scripting language in client side web pages
>> instead of Javascript:
>> http://code.google.com/p/brython/
>> http://www.brython.info/
>>
>
> Brython looks interesting. After the joy of learning it I have to find a
> use for Python, and it appears even Django uses JS as the scripter.
> Probably so folks can use jQuery, which was a great idea, but is now being
> polluted by endless jQuery popups that have replaced the HTML popups I
> block. You will never get away from all popups unless you use Lynx ;')
>
> --
> Jim
> "Would you use Internet Explorer if someone put a gun to your head?"
> "How big is the gun?"
>
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] producing PDF files

2013-06-11 Thread Francois Dion
http://www.xhtml2pdf.com/

Started life as pisa. Very easy to work with.

Francois
--
www.pyptug.org  -  raspberry-python.blogspot.com  -  @f_dion


On Tue, Jun 11, 2013 at 5:53 AM, Khalid Al-Ghamdi wrote:

> Hi,
>
> Do you know of a python module for converting text files to PDF format?
>
> thanks
>
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] sound implementation problems

2013-06-13 Thread Francois Dion
I'd start with something simple first, to make sure you have sound output
etc. Run python interactively in the directory you have your wav file. At a
minimum, you need to import pygame, init the mixer (args are not really
needed, but I'll use what you had), set up the sound file and finally, play
it:

>>> import pygame
>>> pygame.mixer.init(22050,-16,2,4096)
>>> snd = pygame.mixer.Sound("bach-cello-suite-1.wav")
>>> music = snd.play()

music will start playing in the background. To check if the music is still
playing:

>>> music.get_busy()
1
>>> music.get_busy()
1
>>> music.get_busy()
0

And that's that. In your code, your run() function was probably a method
taken out of a class where sound returns a filename and seek(0) seeks to
the beginning of a file. You are missing the rest of the class. But, like I
said, you really only need 4 lines to play a wav file.

BTW, nice russian машинистка in the background image of your site.

Francois
--
www.pyptug.org  -  raspberry-python.blogspot.com  -  @f_dion



On Thu, Jun 13, 2013 at 1:21 PM, jessica peters wrote:

> Hi
>
> I'm about 2 yrs into studying Python - started with "Hello World", and I'm
> working with v 2.5.1 right now.  The past year I've begun trying to write
> my own interactive fiction.  That works pretty well, but now I'm attempting
> to put some music into programs (I thought background music would be good),
> and I'm running into roadblocks.
>
> I've tried several different things for this, and come up with either my
> text that comes to a halt eventually at an error message (can't read from
> the files or mixer isn't initialized are the most common ones), or a
> completely blank screen with no sound.  I've tried both .mp3 files and .wav
> ones, neither works for this.
>
> Here's the most recent code I've attempted:
>
> import pygame , sys
> import random
> size=[500,500]
> def run(self):
> import pygame.mixer
> pygame.mixer.init(22050, -16, 2, 4096)
> self.sound.seek(0)
> snd = pygame.mixer.Sound(self.sound)
> pygame.mixer.Sound.play("bach-cello-suite-1.wav")
> musicPlaying = True
>
> Any ideas would  be appreciated.  Thanks.
>
> my website: http://jahowe.com
>
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] How to write on Planet Python

2013-07-17 Thread Francois Dion
On Jul 17, 2013, at 7:12 AM, Karan Goel  wrote:

> How do I publish a post on Planet Python (http://planet.python.org/). I 
> cannot find any information for contributors.


At the bottom of the list of blogs is this:

To request addition or removal:
e-mail planet at python.org (note, responses can take up to a few days)

Now, make sure you subscribe a URL that feeds python articles, not your 
vacation pictures or a restaurant review... You can tag your python posts and 
provide the url for that tag.

Francois
--
Www.pyptug.org. -  raspberry-python.blogspot.com. -  @f_dion___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] script in Raspberry pi python

2013-07-29 Thread Francois Dion
Dont edit unix files on windows, else you might end up with that problem.

It is looking for python^M and not python. Edit with vi and delete the 
control-M character.

Also, If you need to edit a file with a GUI but have the raspberry pi headless 
check out:

http://raspberry-python.blogspot.com/2012/09/sidekick.html

http://raspberry-python.blogspot.com/2012/09/sidekick-2.html

Then you can edit with geany or the like, but display on your windows pc.
Francois

Sent from my iPad

On Jul 25, 2013, at 2:45 PM, Kirk Bailey  wrote:

> which python 
> /usr/bin/python
> root@KirksPiBox1:/home/pi: ./RR.py
> bash: ./RR.py: /usr/bin/python^M: bad interpreter: No such file or directory
> root@KirksPiBox1:home/pi:_
> 
> 
> 
> 
> On 7/25/2013 1:47 PM, Walter Prins wrote:
>> Hi,
>> 
>> 
>> On 25 July 2013 18:02, Kirk Bailey  wrote:
>> 
>> On 7/23/2013 9:42 PM, Amit Saha wrote:
>> On Wed, Jul 24, 2013 at 11:13 AM, Kirk Bailey  
>> wrote:
>> Python works fine in pi. script works fine IF I invoke it high church:
>> python ./RR.py
>> 
>> but this fails: ./RR.py
>> the shebang is
>> #!/usr/bon/python
>> bon -> bin
>> right.
>> 
>> 
>> Also, don't forget to chmod +x RR.py
>> already done... I think... yep, 755. RWXR.XR.X!
>> 
>> Therefore, Fhat the Wuck over?
>> 
>> Still not working?  Strange.  Any error message?  What OS?
>> 
>> What's the output of the following entered at the shell prompt:
>> 
>> which python
>> 
>> 
>> 
>> Walter
> 
> -- 
> 
> -Shaboom.
> 
> Kirk Bailey
> CEO, Freehold Marketing LLC
> http://www.OneBuckHosting.com/ 
> 
> Fnord!
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Python

2013-08-15 Thread Francois Dion
On Aug 15, 2013 8:04 PM, "Jake Wohldmann"  wrote:
>
>  I was also wondering if I could use python on my android phone.
>

Http://qpython.com

And then, there is the browser based approach. For example, see
http://raspberry-python.blogspot.com
That's using Brython and the interactive mode. Works on iPhone, iPad,
android (tested it on my nexus 7 HD)

Francois
--
www.pyptug.com   -  raspberry-python.blogspot.com  -  @f_dion
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] most useful ide

2014-02-03 Thread Francois Dion
On Sun, Feb 2, 2014 at 3:25 AM, Ian D  wrote:

> Are there any recommendations for python ide's
>

Since you mentionned windows and lightweight and autocompletion, i'd take a
look at ninja-ide (http://ninja-ide.org/). It is relatively lightweight. In
my case, I use pycharm for larger projects (vcs integration etc), scribes
for a graphical editor for one off scripts, vim and bpython (very nice for
exploring - autocompletion and autodoc) from the command line, brython
console in the web browser and ipython notebook for matlab type "coding"
(exploration). Another suggestion would be sublimetext. It is a text
editor, but it can handle multiple tabs and it has a folder browser. You
can also run the code (ctrl-b) etc. I've used it, but not in the past 6
months. And you might also want to look at pythonxy, canopy and anaconda
for a simpler install experience under windows.

Francois
---
www.pyptug.org  -  raspberry-python.blogspot.com  -  @f_dion
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Suggestions Please

2014-10-07 Thread Francois Dion
El Oct 6, 2014, a las 6:42 PM, Phillip Pugh  escribió:

> I am trying to decide if Python is the right toolset for me. I do a lot of 
> data analytics. Over the years I have used a lot of SQL and VBA, but the data 
> sources are getting bigger. I am thinking Python may be what I need to use, 
> but I am in the early stages of getting to know Python.  Can you point me to 
> a really good, intuitive resource for getting up to speed with data.

If you are doing data analytics, particularly iterative stuff, get to know 
ipython notebook and pandas. 

http://nbviewer.ipython.org/github/twiecki/financial-analysis-python-tutorial/blob/master/1.%20Pandas%20Basics.ipynb

To have an overall feel for ipython notebook and python in general for matlab 
style notebooks:

https://github.com/ipython/ipython/wiki/A-gallery-of-interesting-IPython-Notebooks

Francois
--
raspberry-python.blogspot.com - www.pyptug.org - @f_dion
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Python serial interface

2015-04-01 Thread Francois Dion
Pyserial is python 2.x and 3.x compatible. It is very widely used and is
stable.

http://pyserial.sourceforge.net/

What is your application? Sometimes you can use a higher level module that
makes use of pyserial.

Francois
--
raspberry-python.blogspot.com - www.pyptug.org - www.3DFutureTech.info -
@f_dion
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Python serial interface

2015-04-01 Thread Francois Dion
On Wed, Apr 1, 2015 at 11:01 AM, Colin Ross 
wrote:

> Hi Francois,
>
> Thank you for the fast reply! I am looking to control a brushless servo
> motor (
> http://www.aerotech.com/product-catalog/motors/rotary-motors/bms-series.aspx)
> that drives a rotary stage.
>

These motors are not controlled by serial, you'll need a brushless
controller. In turn the controller might be or not serial, or ip or
something else altogether (PWM is typical). They do have an rs-422
connection, but that is for a feedback signal. So you are building a
feedback control system. If you google that and python you'll find several
useful references, including a design and analysis module (but not control):

https://pypi.python.org/pypi/control/0.6.6
http://sourceforge.net/projects/python-control/

Nothing out of the box for your application, obviously. Also, the motor
control itself will depend on the microprocessor hardware you are using and
the motor controller. Assuming PWM, the raspberry pi has a software PWM
module in Python. Same with micropython. Anything else is pretty much DIY.

As for the overall concept of control systems, Chapter 9 of "Real World
Instrumentation" ( http://shop.oreilly.com/product/9780596809577.do ) will
give you an overview of what is involved (with some python example, but not
directly applicable to your system).

Francois
--
raspberry-python.blogspot.com - www.pyptug.org - www.3DFutureTech.info
 - @f_dion
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] airflow dag

2017-05-28 Thread Francois Dion
My mailbox if full of similar stories: companies dumping airflow on their
ETL (or similar) group. Those who knew Python succeeded, those who didn't
failed, and some even moved to other companies because they couldn't cope
with all this complexity dumped on them all at once.

Moral of the story, it is best to learn python first, become good at it,
then get into specific tools.

And, of course, this is not specific to a relatively straightforward module
/ application like airflow. I've seen the same with scikit-learn. Same also
in other languages. And to make matters worse, the curricula (and books)
always starts with a crash course in a specific language, then go on and on
about the application, perpetuating the myth that learning the programming
language well is totally unimportant.

Francois

On Sun, May 28, 2017 at 9:46 AM, Alan Gauld via Tutor 
wrote:

> On 28/05/17 04:37, shubham goyal wrote:
> > Does anybody have answer?
>
> You received two answers, both of which asked
> you to try something and get back to us for more
> information. Did you try printing sys.argv?
> What was the result?
>
> And did you try Peter's argparse code?
>
> You still haven't explained what your dag is?
> What library are you using? It may treat args
> in a non standard way, but we can't tell if
> you don't give us the information we need to
> help you.
>
> --
> Alan G
> Author of the Learn to Program web site
> http://www.alan-g.me.uk/
> http://www.amazon.com/author/alan_gauld
> Follow my photo-blog on Flickr at:
> http://www.flickr.com/photos/alangauldphotos
>
>
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor
>



-- 
raspberry-python.blogspot.com - www.pyptug.org - www.3DFutureTech.info -
@f_dion
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Coming from R, what's a good IDE editor? I've tried PyCharm and Spyder

2017-06-03 Thread Francois Dion
PyCharm has support for cell based notebooks, interactive python console
etc. You can set up the layout so it mirrors Rstudio. Spyder should have
installed correctly. How did you install?

Having said that, you should also look into JupyterLab:
https://github.com/jupyterlab/jupyterlab,
YHat's Rodeo: https://www.yhat.com/products/rodeo
and of course, vim + tmux + tmuxp and something like sidecar:
https://github.com/smashwilson/jupyter-sidecar
Enthought's Canopy: https://store.enthought.com/downloads/#default

All of them can be configured to replicate pretty much the same workflow as
rstudio, although there's a cliff waiting when deploying this stuff to
production. I've sat in many conferences and meetups where the speaker is
demoing his code directly in Rstudio and, of course, gets to the point
where there's an undefined variable. "oh yeah, I forgot about that..."

Not a knock against R, just something to be aware of in systems that allow
non linear code execution (like Jupyter notebooks, be it R, Python, Octave,
Coconut or anything else that runs in it).

Also, look into the rpy2 python module and feather-format. That way you can
still go back and forth with R.


Francois



On Fri, Jun 2, 2017 at 1:46 PM, C W  wrote:

> Dear Python list,
>
> I am an R user learning Python. What is a good editor?
>
> 1) Pycharm
> PyCharm evaluates the entire script, I just want to change a few lines in
> the script.
> For example,
>
> import matplotlib.pyplot as plt
> import numpy as np
>
> x = np.arange(0, 1,0.1)
> y = np.sin(2 * np.pi * x)
>
> plt.figure(1)
> plt.clf()
> plt.plot(x, y)
> plt.show()
>
> Now, I want to do a scatter plot, but don't want to generate the data
> again. I just want the "line by line" evaluation like in R and Matlab.
> Basically, you can type in console and add to the existing variables.
>
> 2) Spyder
> Spyder looks a lot like RStudio, I like it! But, it does not have an app
> icon in applications.  I am baffled. I do ~/anaconda/bin/spyder every time.
>
> Am I missing something or is this the way it is?
>
> Thank you very much!
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor
>



-- 
raspberry-python.blogspot.com - www.pyptug.org - www.3DFutureTech.info -
@f_dion
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Raspberry pi 2 python help

2017-06-13 Thread Francois Dion
"These are not the scripts you are looking for"

More seriously, you want to configure your shell. See the linux
documentation project, beginner's guide to bash, chapter 3 in particular:
http://tldp.org/LDP/Bash-Beginners-Guide/html/index.html

Until you login, your shell doesn't even exists, so you cant preemptively
change it before the login. You can do it right at login time, through one
of the files mentioned that chapter.

Francois


On Tue, Jun 13, 2017 at 10:08 AM, DJ VIN Lom  wrote:

> Can i create a script to have my pi change to a certian directory
> automaticlly after booting. I want it to be in a directory so when i ssh
> into it its ready and i dont need to spend time to do it. As well i dont
> want to carry a keyboard mouse and montor
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor
>



-- 
raspberry-python.blogspot.com - www.pyptug.org - www.3DFutureTech.info -
@f_dion
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor