Re: [Tutor] Thread Object integration with GPIO

2017-04-29 Thread boB Stepp
On Sat, Apr 29, 2017 at 1:26 PM, Marc Eymard  wrote:
> Hello there,

> Attached the script I have come up with, which keeps returning multiple
> run time errors whenever I try to fix it.
> I believe there are multiple issues, but at least it gives an idea of
> what I currently want to achieve and how.

This is a plain text only list.  This list does not accept
attachments.  Reduce your code to the minimum necessary to replicate
the problem and put it in the body of your email to Tutor.  Include a
copy and paste of the full error traceback.  Also helpful is what
version of Python you are using and your operating system.  Hopefully
someone here might be able to assist you with your issues.


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


Re: [Tutor] Another set question

2017-04-29 Thread Ben Finney
Phil  writes:

> It took me months to solve come up with a working solution in C++
> whereas I almost have a working solution in Python in a little over a
> week.

Welcome to Python, we're glad to hear of your success!

-- 
 \  “[Entrenched media corporations will] maintain the status quo, |
  `\   or die trying. Either is better than actually WORKING for a |
_o__)  living.” —ringsnake.livejournal.com, 2007-11-12 |
Ben Finney

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


Re: [Tutor] Another set question

2017-04-29 Thread Phil
On Sat, 29 Apr 2017 20:27:17 +1000
Ben Finney  wrote:

> Why is the data in such a state that you can't decide how to use it
> until you know whether it is a set versus a string? Can the data be
> handled differently? We'll need to know what you're trying to achieve,
> to answer properly.

Thank you Ben. A rethink of the problem during the 20 hours since I posted my 
most recent question has led to a solution.

I'm rewriting a C++ program that I wrote 15 years ago to solve sudoko puzzles. 
I'm having some difficulty with the translation in part because of my poorly 
documented code and because Python does some things differently. I've abandoned 
my original translation attempt and have started afresh which is probably a 
good idea. It took me months to solve come up with a working solution in C++ 
whereas I almost have a working solution in Python in a little over a week.

The strings are the given numbers while the sets are the likely candidates.

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


[Tutor] Thread Object integration with GPIO

2017-04-29 Thread Marc Eymard
Hello there,

I have hooked up an ultrasonic sensor to my Raspberry Pi-enabled robot 
in order to get continuous distance-to-obstacle reading.

The sensor is properly connected via GPIO and already reads the distance 
properly when running a simple script.

However, I need to integrate the sensor reading logic to an existing 
script provided by PiBorg called YetiBorg.py

The way I have decided to go about implementing the sensor reading is by 
creating a Thread object and update the distance attribute of this very 
same object from the run() function. The idea is to encapsulate the 
distance reading within the sensor object as much as possible by i. 
creating a sensor/thread object and by ii. avoiding global variables.

Attached the script I have come up with, which keeps returning multiple 
run time errors whenever I try to fix it.
I believe there are multiple issues, but at least it gives an idea of 
what I currently want to achieve and how.

Can a charitable soul advise whether my approach makes sense and whether 
I am using the right type of object for the task at hands?

I am looking for guidance and willing try completely different 
approach/objects if necessary.

Thanks in advance for sending me into the right direction.
Marc

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


Re: [Tutor] Working with APIs - understanding the basics (Python 3.5)

2017-04-29 Thread Alan Gauld via Tutor
On 29/04/17 18:13, Rafael Knuth wrote:
> can anyone recommend good resources? I am primarily in search of
> simple, clean code examples & practical usecases (Google APIs for
> example). 

An API is just a set of classes or functions.
The Python standard library is an API.

You already have lots of examples and documentation
for the standard library.

What exactly is it you are looking for?
If I describe, for example, the API to WxPython (for
building GUIs) that will probably not help you unless
you want to build a GUI.

Similarly if I describe Twisted's API (for writing
networking programs) that won't help unless you want to
write a network server or somesuch.

Is there a specific API you have in mind (you mention
Google - is that because you want to use it or just
because its one you've heard about?)? Or is it just
the concept of APIs?

If the latter stick with the standard library, or a
sub-set of it. For example the os package provides
an API into your operating system. Try exploring that.
Start with the os module documentation.

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


[Tutor] Working with APIs - understanding the basics (Python 3.5)

2017-04-29 Thread Rafael Knuth
can anyone recommend good resources? I am primarily in search of
simple, clean code examples & practical usecases (Google APIs for
example). Thanks. Right now, I am learning at Codecademy,
Dataquest.io, Datacamp and from "Python Crash Course" by Eric
Matthews.

I am new to programming, Python is my first language.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Another set question

2017-04-29 Thread Ben Finney
Phil  writes:

> Thank you Ben and Martin for your detailed replies. I was debating
> whether or not to post my question at all because it looked vague,
> even to me.

That's not the issue; the question was posed clearly enough. The problem
is that your purpose is opaque, and we have a strong suspicion your
approach is not well suited to the purpose.

> This a simplified version of what I had in mind:

Thank you for the example code. However the same issue remains:

Why is the data in such a state that you can't decide how to use it
until you know whether it is a set versus a string? Can the data be
handled differently? We'll need to know what you're trying to achieve,
to answer properly.

-- 
 \  “Compulsory unification of opinion achieves only the unanimity |
  `\of the graveyard.” —Justice Roberts in 319 U.S. 624 (1943) |
_o__)  |
Ben Finney

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


Re: [Tutor] Another set question

2017-04-29 Thread Phil
On Fri, 28 Apr 2017 19:42:36 -0700
"Martin A. Brown"  wrote:

> 
> Hello and greetings Phil,
> 
> >> I'm trying to implement a conditional branch based on a variable
> >> type.
> >
> >This is often (not always) a mistake, in Python. So the question
> >needs to be asked: What makes you think that condition is a
> >requirement?
> >
> >So, I suspect you will need to explain better what larger problem you
> >are trying to solve, and re-consider whether the condition you're
> >trying to test is actually going to help that purpose.

Thank you Ben and Martin for your detailed replies. I was debating whether or 
not to post my question at all because it looked vague, even to me.

This a simplified version of what I had in mind:

alist = [1,2,9,6]

alist[2] = set({4})

for i in range(4):
if i is a set:
do this

1, 2 and 6 are given numbers and the set containing 4 is what I want to operate 
on.

My alternative method that I mentioned in my previous question compares each 
alist[i] number to another list of given numbers. If alist[i] does not appear 
in the given number list then it must be a set. At this point of the program 
I'm only interested in sets that have only have one member. Sets with more than 
one member are dealt with later.

I'm nearly certain that this is the method that I should continue to pursue, 
unless someone can offer a cleverer solution.

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