Albert-Jan Roskam | 20 Apr 22:05 2015

Is it possible to "backport" the datetime module of Python 3.3 to Python 3.2?

Hi,

My Raspberry Pi 2 comes with Python 3.2 (and 2.7). I run some code that uses the datetime module but I get an error:

"AttributeError: 'datetime.datetime' object has no attribute 'timestamp'". On
https://docs.python.org/3/whatsnew/3.3.html I see: "New datetime.datetime.timestamp() method:
Return POSIX timestamp corresponding to thedatetime instance." Is upgrading Python 3.3 or higher my
only option, or is it somehow possible to use the newer version of the datetime library for Python 3.2? I do
not want to modify the source code of the library that causes the error (pysolar).

Thanks!

 
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 <at> python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor

(Continue reading)

Alan Gauld | 20 Apr 18:16 2015

Re: Life Grid Implementation

On 20/04/15 13:59, niyana morgan wrote:
> I don't understand how to do this. I attempted with my code and hoped a
> tutor could help me with this

Always write code that runs. Then fix the mistakes as they
happen. That way you only have a few lines of code to look
at. Your code is far too big and intertwined to be able
to debug easily.

Look at your specification:
• SparseLifeGrid() Creates a new infinite-sized game grid
    with all cells initially dead.
...
  • clearCell(row, col) Clears the individual cell (row, col)
    and sets it to dead. If the cell is already dead, no action
    is taken.
  • setCell(row, col) Sets the indicated cell (row, col)
    to be alive. If the cell is already alive, no action is taken.
....

I suggest you start over with a class definition and an init().
See if you can create an instance and if it has the
fields you expect. Thats your first API bullet done.

Once you can do that create the methods needed to populate
it with data (setCell()) and clear a cell(clearCell()).
Nothing else, just those two methods. Get them working.
Now you have three parts of your assignment done.

Only when you can do those things correctly attempt one of the remaining 
(Continue reading)

Alex Kleider | 20 Apr 17:24 2015
Picon

introspection

Does python provide the introspective ability to retrieve the name to 
which an object is bound?

For example:
$ python3
Python 3.4.0 (default, Apr 11 2014, 13:05:18)
[GCC 4.8.2] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> a = 69
>>> print("Identifier <{}> is bound to {}.".format(a.__name__, a))
Traceback (most recent call last):
   File "<stdin>", line 1, in <module>
AttributeError: 'int' object has no attribute '__name__'

_______________________________________________
Tutor maillist  -  Tutor <at> python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor

Jim Mooney | 20 Apr 09:44 2015
Picon

bin to dec conversion puzzlement

I can't seem to get my head around this 'simple' book example of
binary-to-decimal conversion, which goes from left to right:

B = '11011101'
I = 0
while B:
    I = I * 2 + int(B[0])
    B = B[1:]

print(I)
>>> 221

My thought was to go from right to left, multiplying digits by successive
powers of two, and adding, like so:

B = '11011101'
sum = 0

for exp, num in enumerate(reversed(B)):
    sum += int(num) * 2**exp

print(sum)
>> 221

Both methods work but I just can't see how the first one does. Am I missing
something obvious here?

--

-- 
Jim
_______________________________________________
(Continue reading)

niy mor | 20 Apr 02:36 2015
Picon

Life Grid Implementation

Is my code completing the assignment??? I need some *guidance* on
completing my assignment.

My Assignment:
A sparse life grid is used to store and represent the area in the game of
Life that contains organisms. The grid contains a rectangular grouping of
cells divided into an infinite number of rows and columns. The individual
cells, which can be alive or dead, are referenced by integer row and column
indices. The operations defined for the ADT are as follows:
• SparseLifeGrid() Creates a new infinite-sized game grid with all cells
initially dead.
 • minRange() Returns a 2-tuple (minrow, mincol) that contains the minimum
row index and the minimum column index that is currently occupied by a live
cell. The tuple (0, 0) is returned if there are no live cells.
 • maxRange() Returns a 2-tuple (maxrow, maxcol) that contains the maximum
row index and the maximum column index that is currently occupied by a live
cell. The tuple (0, 0) is returned if there are no live cells.
 • clearCell(row, col) Clears the individual cell (row, col) and sets it to
dead. If the cell is already dead, no action is taken.
 • setCell(row, col) Sets the indicated cell (row, col) to be alive. If the
cell is already alive, no action is taken.
 • isLiveCell(row, col) Returns a Boolean value indicating if the given
cell (row, col) contains a live organism.
• numLiveNeighbors(row, col) Returns the number of live neighbors for the
given cell (row, col). The neighbors of a cell include all of the cells
immediately surrounding it in all directions.

My Attempt Code:
class SparseLifeGrid :

(Continue reading)

boB Stepp | 20 Apr 05:34 2015
Picon

How to close a Tkinter window from a different thread?

I am not certain that my terminology is correct in the subject line.
Let me explain my issue.

Scenario A:
1) I start out inside a commercial software environment (Abbreviated
CSA henceforth).
2) I initiate a script in the CSA's scripting language.
3) This script calls an external Python script.com
4) This Python script generates a Tkinter window, populating it with
information from the CSA.
5) Control will not pass back to the CSA until the Tkinter window is
closed. Because of this, none of the CSA's tools can be used until the
Tkinter window is closed.

Scenario B:
1) I start out inside the CSA.
2) I initiate a script in the CSA's scripting language.
3) This script calls an external Python script in a new thread.
4) This Python script generates a Tkinter window, populating it with
information from the CSA.
5) Control returns to the CSA while the Tkinter window is populating
itself. The CSA's tools can be used while the Tkinter window remains
open displaying its information.

My users want scenario B to occur. This way they can refer to the
Tkinter window's info and make changes to their plan based on this
info. However! Once they make their changes they will want to rerun
the same Python script. This would then result in TWO Tkinter windows
being open, one displaying the old info, the new one with the
post-changes info. This is not acceptable.
(Continue reading)

boB Stepp | 20 Apr 03:03 2015
Picon

OT: Is there a good book that covers the history/evolution of software? [Inspired by the thread: lists, name semantics]

In the beginning (I assume.) there was machine code and only machine
code. And I imagine this was not very good. Then I assume the next
step was assembler, which probably only moderated the (then) tedium of
coding. Then real high level languages were started to be developed,
and this was very good. And then there were various new programming
paradigms developed, and so on. What I am wondering is, is there a
good book that covers in relatively good detail how we started at the
most primitive level, machine code, and evolved to our current
wonderful cornucopia of languages, operating systems, etc.? As the
different threads reveal bits and pieces of the low level guts of
Python, I am becoming more and more fascinated about how all of this
is managed. Just the brief discussion of garbage collection details
going on I find quite interesting.

--

-- 
boB
_______________________________________________
Tutor maillist  -  Tutor <at> python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor

Dave Angel | 20 Apr 01:19 2015

Re: lists, name semantics

On 04/19/2015 06:28 PM, Joel Goldstick wrote:
> On Sun, Apr 19, 2015 at 6:23 PM, boB Stepp <robertvstepp <at> gmail.com> wrote:
>> On Sun, Apr 19, 2015 at 4:05 PM, Dave Angel <davea <at> davea.name> wrote:
>>> On 04/19/2015 03:08 PM, boB Stepp wrote:
>>>>
>>
>>>> Or is the real point that we are adding an abstraction
>>>> layer so we don't even have to think about where objects are
>>>> physically stored in RAM?
>>>
>>>
>>> Somebody keeps track, but the address is not necessarily constant, and not
>>> necessarily stored in any references.  The references (bindings) are
>>> abstract, and the details are unimportant to the user.  For example, the
>>> jython system does not use addresses at all.  And an object gets moved
>>> around from time to time without its references knowing it.
>>
>> The last sentence in this paragraph has me intrigued. Why would an
>> object, once it has been created, be moved? What practical benefit
>> does doing this give?
>>
>> boB
>
> I'm guessing memory management.  You want to have large contiguous
> blocks of memory available for large objects.  If a small object is
> surrounded by available memory, you might want to move it to some
> smaller empty spot.

Good answer.  The java jvm garbage collector is free to move blocks 
around to defrag the free space.
(Continue reading)

Jim Mooney | 19 Apr 03:56 2015
Picon

sample dictionairies

Where could I download Python sample dictionaries on different subjects.
They're hard to type and I can only do small, limited ones to practice with.

--

-- 
Jim

The probability of a piano falling on my head is 50%. After it falls on my
head the probability is 100%. My confidence in the piano hitting my head
has increased.
This is Bayesian statistics in a nutshell.
_______________________________________________
Tutor maillist  -  Tutor <at> python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor

Bill Allen | 18 Apr 05:16 2015
Picon

lists, name semantics

If I have a list defined as my_list = ['a','b','c'], what is the is
differnce between refering to it as my_list or my_list[:]?   These seem
equivalent to me.  Is that the case?  Is there any nuance I am missing
here?   Situations where one form should be used as opposed to the other?

Thanks,
Bill Allen
_______________________________________________
Tutor maillist  -  Tutor <at> python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor

Samuel VISCAPI | 17 Apr 10:39 2015
Picon

Unicode encoding and raw_input() in Python 2.7 ?


Hi,

This is my first post to that mailing list if I remember correctly, so
hello everyone !

I've been stuck on a simple problem for the past few hours. I'd just
like raw_input to work with accentuated characters.

For example:

firstname = str.capitalize(raw_input('First name: '))

where firstname could be "Valérie", "Gisèle", "Honoré", etc...

I tried -*- coding: utf-8 -*-, u'', unicode(), but to no avail...

I'm using str.capitalize and str.lower throughout my code, so I guess
some encoding / decoding will also be necessary at some point.

Thanks a lot for your help !

Cheers, Samuel


Gmane