What kind of "thread safe" are deque's actually?

2023-03-27 Thread Travis Griggs
A while ago I chose to use a deque that is shared between two threads. I did so 
because the docs say:

"Deques support thread-safe, memory efficient appends and pops from either side 
of the deque with approximately the same O(1) performance in either direction.”

(https://docs.python.org/3.11/library/collections.html?highlight=deque#collections.deque)

Earlier today, looking through some server logs I noticed that from time to I’m 
getting a

RuntimeError: deque mutated during iteration

I guess this surprised me. When I see “thread safe”, I don’t expect to get 
errors.

Interestingly the error also only started showing up when I switched from 
running a statistics.mean() on one of these, instead of what I had been using, 
a statistics.median(). Apparently the kind of iteration done in a mean, is more 
conflict prone than a median?

I’ve got a couple ways I can work around this. But I was surprised.
-- 
https://mail.python.org/mailman/listinfo/python-list


mapLast, mapFirst, and just general iterator questions

2022-06-14 Thread Travis Griggs
I want to be able to apply different transformations to the first and last 
elements of an arbitrary sized finite iterator in python3. It's a custom 
iterator so does not have _reversed_. If the first and last elements are the 
same (e.g. size 1), it should apply both transforms to the same element. I'm 
doing this because I have an iterator of time span tuples, and I want to clamp 
the first and last elements, but know any/all of the middle values are 
inherently in range.

A silly example might be a process that given an iterator of strings, chops the 
the outer characters off of the value, and uppercases the final value. For 
example:


def iterEmpty():
return iter([])

def iter1():
yield "howdy"

def iter2():
yield "howdy"
yield "byebye"

def iterMany():
yield "howdy"
yield "hope"
yield "your"
yield "day"
yield "is"
yield "swell"
yield "byebye"

def mapFirst(stream, transform):
try:
first = next(stream)
except StopIteration:
return
yield transform(first)
yield from stream

def mapLast(stream, transform):
try:
previous = next(stream)
except StopIteration:
return
for item in stream:
yield previous
previous = item
yield transform(previous)

def main():
for each in (iterEmpty, iter1, iter2, iterMany):
baseIterator = each()
chopFirst = mapFirst(baseIterator, lambda x: x[1:-1])
andCapLast = mapLast(chopFirst, lambda x: x.upper())
print(repr(" ".join(andCapLast)))


This outputs:

''
'OWD'
'owd BYEBYE'
'owd hope your day is swell BYEBYE'

Is this idiomatic? Especially my implementations of mapFirst and mapList there 
in the middle? Or is there some way to pull this off that is more elegant?

I've been doing more with iterators and stacking them (probably because I've 
been playing with Elixir elsewhere), I am generally curious what the 
performance tradeoffs of heavy use of iterators and yield functions in python 
is. I know the argument for avoiding big list copies when moving between 
stages. Is it one of those things where there's also some overhead with them, 
where for small stuff, you'd just be better list-ifying the first iterator and 
then working with lists (where, for example, I could do the first/last clamp 
operation with just indexing operations).
-- 
https://mail.python.org/mailman/listinfo/python-list


Polymorphic imports

2021-09-21 Thread Travis Griggs
I guess this is kind of like mocking for testing. I have a simple module that's 
imported in a number of other spots in my program. There's a condition in the 
OS/filesystem where I'd like to import a polymorphically compatible variant of 
the same module. Can this be accomplished in a sort of once-and-only once spot?

For example, consider something like this:

client/
  module_a
  module_a_prime
lib/
  paths
   lib_a
   lib_b
   ...
model/
  model_a
  model_b
  ...
top_level_a
top_level_b
...


I have a number of imports of module_a. I have a paths module that isolates all 
of my file system access, and that's where the determination can be made which 
one to use, so I tried to do something like:

def dynamic_client_module():
   return client.module_a_prime if the_condition_occurs else client.module_a


Hoping that I could do something like

from lib import paths
import paths.dynamic_client_module()

But this seems to not work. Import can only take real modules? Not programatic 
ones?

Is there a Not-Too-Evil-Way(tm) to add a level of programmatic indirection in 
the import declarations? Or some other trick from a different angle? 
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Fun Generators

2021-04-23 Thread Travis Griggs



> On Apr 23, 2021, at 05:55, Frank Millman  wrote:
> 
> On 2021-04-23 7:34 AM, Travis Griggs wrote:
>> Doing an "industry experience" talk to an incoming class at nearby 
>> university tomorrow. Have a couple points where I might do some "fun things" 
>> with python. Said students have been learning some python3.
>> I'm soliciting any *fun* generators people may have seen or written? Not so 
>> much the cool or clever ones. Or the mathematical ones (e.g. fib). Something 
>> more inane and "fun". But still showcasing generators uniqueness. Short and 
>> simple is good.
>> Thanks in advance!
> 
> Have you looked at this?
> 
> http://www.dabeaz.com/generators/
> 
> Frank Millman
> 
> -- 
> https://mail.python.org/mailman/listinfo/python-list


I hadn't. But now I have. These are really cool. But not as whimsical/simple as 
I would have hoped. They're actually useful :)
-- 
https://mail.python.org/mailman/listinfo/python-list


Fun Generators

2021-04-22 Thread Travis Griggs
Doing an "industry experience" talk to an incoming class at nearby university 
tomorrow. Have a couple points where I might do some "fun things" with python. 
Said students have been learning some python3.

I'm soliciting any *fun* generators people may have seen or written? Not so 
much the cool or clever ones. Or the mathematical ones (e.g. fib). Something 
more inane and "fun". But still showcasing generators uniqueness. Short and 
simple is good.

Thanks in advance!
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Canonical conversion of dict of dicts to list of dicts

2021-03-30 Thread Travis Griggs


> On Mar 30, 2021, at 12:11, Stestagg  wrote:
> 
> For completeness, from 3.5 onwards, you can also do the following:
> 
> [{'name': n, **d} for n, d in dod.items()]
> 

Reading through these, personally I like this one best. I'm curious what about 
it was enabled in 3.5? Was **kwarg expansion inside a dict literal not possible 
before then? Anyway, I like that it uses simple elemental parts that have been 
around a long long time in Python.

-- 
https://mail.python.org/mailman/listinfo/python-list


Code Formatter Questions

2021-03-28 Thread Travis Griggs
I've been looking into using a code formatter as a code base size has grown as 
well as contributing developers. I've found and played with autopep, black, and 
yapf. As well as whatever pycharm has (which may just be gui preferences around 
one of those 3).

I have 2 questions:
1) Are there any major other formatters that I can/should look at? I see some 
"online" pretty printers, but I'm after something I can run on whole recursive 
directories of code.

2) I use more and type annotations (at least at the trivial level). But I like 
to have variable annotations tightly bound to the identifier, kind of like a 
subscript. So I want to see 

  def foo_bar(baz:int) -> bool:
yak:str = 'howdy mates'

And NOT 

  def foo_bar(baz: int) -> bool:
yak: str = 'howdy mates'

In other cases though (dictionaries for example), I'm fine with (and prefer) 
the spacing.

Is there anyway to make any of these formatters do this?

We write a lot of Swift and Kotlin as well as which uses the same general 
syntax (identifier:Type) for type annotation, and we'd like to have some 
consistency across the styles (we pack the couplets in those two).


-- 
https://mail.python.org/mailman/listinfo/python-list


How do/can I generate a PKCS#12 file the cryptography module?

2019-02-13 Thread Travis Griggs
I’m using the cryptography module (https://cryptography.io/en/latest/) to try 
and generate some cert/key/identities.

It's pretty easy using said module to generate the contents of .pem file for a 
private key:

keyPEMBytes = privateKey.private_bytes( 
encoding=serialization.Encoding.PEM,
format=serialization.PrivateFormat.TraditionalOpenSSL,
encryption_algorithm=serialization.NoEncryption())

It’s also easy to generate the contents of a .cer/.pem file for an associated 
cert:

certBytes = certificate.public_bytes(encoding=serialization.Encoding.PEM)

But I need them (and their chain) balled up on a single .p12 (PKCS12) file. 
Said module documents how to parse/consume PKCS12 formats, but nothing (that I 
can find) about how one can generate them.

My understanding of PKI stuff is hit and miss though, so maybe I'm just not 
searching the right keyword in the documentation?

I can create the .p12 file at the command line on Linux using

openssl pkcs12 -export -out myIdentity.p12 -inkey myPrivKey.pem -in 
myCert.crt -certfile myCertChain.crt

So I could just wrap calls like this with subprocess/cmd and mess with 
tempfiles/pipes. I was hoping to keep it all in memory/python though.

Is there a different python TLS library that I should be considering, that can 
do this?

(stack overflow version if you’re into the points and all that: 
https://stackoverflow.com/questions/54677841/how-do-can-i-generate-a-pkcs12-file-using-python-and-the-cryptography-module)


-- 
https://mail.python.org/mailman/listinfo/python-list


More elegant way to avoid this hacky implementation of single line reduce for grouping a collection?

2019-01-25 Thread Travis Griggs
Yesterday, I was pondering how to implement groupby, more in the vein of how 
Kotlin, Swift, Objc, Smalltalk do it, where order doesn’t matter. For example:

def groupby(iterable, groupfunc):
result = defaultdict(list)
for each in iterable:
result[groupfunc(each)].append(each)
return result

original = [1, 2, 3, 4, 5, 1, 2, 4, 2]
groupby(original, lambda x: str(x)) ==> {‘1’: [1, 1], ‘2’: [2, 2, 2], ‘3’: 
[3], ‘4’: [4, 4], ‘5’: [5]}

Easy enough, but I found myself obsessing about doing it with a reduce. At one 
point, I lost sight of whether that was even a better idea or not (the above is 
pretty simple); I just wanted to know if I could do it. My naive attempt didn’t 
work so well:

grouped = reduce(
lambda grouper, each: grouper[str(each)].append(each),
allValues,
defaultdict(list))

Since the result of the append() function is None, the second reduction fails, 
because the accumulator ceases to be a dictionary.

I persisted and came up with the following piece of evil, using a tuple to move 
the dict reference from reduction to reduction, but also force the (ignored) 
side effect of updating the same dict:

grouped = reduce(
lambda accum, each: (accum[0], accum[0][str(each)].append(each)),
allValues,
(defaultdict(list), None))[0]

My question, only for the sake of learning python3 fu/enlightenment, is there a 
simpler way to do this with a reduce? I get there’s lots of way to do a 
groupby. The pursuit here is what’s the simplest/cleverest/sneakiest way to do 
it with reduce, especially if the quality that gorupfunc (str() in this 
example) is only called once per item is persevered.


-- 
https://mail.python.org/mailman/listinfo/python-list


Simplest way to clobber/replace one populated directory with another?

2018-05-15 Thread Travis Griggs
I have a directory structure that might look something like:

Data
Current
A
B 
C 
Previous
A 
X

In as simple/quick a step as possible, I want to rename Current as Previous 
including the contents and wiping out the original such that it is now:

Data
Previous
A
B
C

I've tried something like:

from pathlib import Path
src = Path('Data/Current’)
dest = Path('Data/Previous’)
src.replace(dest)

The docs led me to hope this would work:

"If target points to an existing file or directory, it will be 
unconditionally replaced.”

But it *does* appear to be conditional. I get a "Directory not empty" 
exception. I guess I could recursively delete the ‘Previous' directory first. 
Is that basically the only solution? Or is there a better way to achieve this?

(I prefer `pathlib`, but if `os` or `shutil` is the better hammer here, I'm not 
opposed to them)

(I am running on Linux)
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Most pythonic way to implement byte stuffing algorithm

2018-04-17 Thread Travis Griggs


> On Apr 17, 2018, at 11:15 AM, MRAB <pyt...@mrabarnett.plus.com> wrote:
> 
> On 2018-04-17 17:02, Travis Griggs wrote:
>> I posted this on SO, but… yeah…
>> I'm doing some serial protocol stuff and want to implement a basic byte 
>> stuffing algorithm in python. Though really what this really generalizes to 
>> is “what is the most pythonic way to transform one sequence of bytes where 
>> some bytes are passed through 1:1, but others are transformed to longer 
>> subsequences of bytes?” I’m pretty sure this rules out the use of 
>> transform() which expects a 1:1 mapping.
> [snip]
> There are only 256 possible input bytes, so just put them into a dict and 
> look them up.
> -- 
> https://mail.python.org/mailman/listinfo/python-list


So something like this?

LUT = list(bytes([x]) for x in range(256))
LUT[PacketCode.Escape] = bytes([PacketCode.Escape, PacketCode.Escape ^ 0xFF])
LUT[PacketCode.Start] = bytes([PacketCode.Escape, PacketCode.Start ^ 0xFF])
LUT[PacketCode.Stop] = bytes([PacketCode.Escape, PacketCode.Stop ^ 0xFF])
def stuff6(bits):
   return b''.join(LUT[x] for x in bits)

-- 
https://mail.python.org/mailman/listinfo/python-list


Most pythonic way to implement byte stuffing algorithm

2018-04-17 Thread Travis Griggs
I posted this on SO, but… yeah… 

I'm doing some serial protocol stuff and want to implement a basic byte 
stuffing algorithm in python. Though really what this really generalizes to is 
“what is the most pythonic way to transform one sequence of bytes where some 
bytes are passed through 1:1, but others are transformed to longer subsequences 
of bytes?” I’m pretty sure this rules out the use of transform() which expects 
a 1:1 mapping.


So far, I've come with 5 different approaches, and each of them has something I 
don't like about it:

1 Via Generator

def stuff1(bits):
for byte in bits:
if byte in _EscapeCodes:
yield PacketCode.Escape
yield byte ^ 0xFF
else:
yield byte

This may be my favorite, but maybe just because I'm kind of fascinated by yield 
based generators. I worried that the generator would make it slow, but it's 
actually the second fastest of the bunch.


2 Simply bytes()

def stuff2(bits):
result = bytes()
for byte in bits:
if byte in _EscapeCodes:
result += bytes([PacketCode.Escape, byte ^ 0xFF])
else:
result += bytes([byte])
return result

Constantly has to create single element arrays just to throw them out because 
I'm not aware of any "copy with one additional element" operation. It ties for 
the slowest of the bunch.


3 Use bytearray()

def stuff3(bits):
result = bytearray()
for byte in bits:
if byte in _EscapeCodes:
result.append(PacketCode.Escape)
result.append(byte ^ 0xFF)
else:
result.append(byte)
return result

Seems better than the direct bytes() approach. Actually slower than the yield 
generator and can do one byte at a time (instead of needing intermediate 1 
element collections). But it feels brutish. It's middle of the pack performance.


4 BytesIO()

def stuff4(bits):
bio = BytesIO()
for byte in bits:
if byte in _EscapeCodes:
bio.write(bytes([PacketCode.Escape, byte ^ 0xFF]))
else:
bio.write(bytes([byte]))
return bio.getbuffer()

I like the stream based approach here. But it is annoying that there doesn't 
seem to be something like a write1() API that could just add 1 byte, so I have 
to make those intermediate bytes again. If there was a "write single byte", I'd 
like this one. It ties for slowest.


5 Use replace()

def stuff5(bits):
escapeStuffed = bytes(bits).replace(bytes([PacketCode.Escape]), 
bytes([PacketCode.Escape, PacketCode.Escape ^ 0xFF]))
stopStuffed= escapeStuffed.replace(bytes([PacketCode.Stop]), 
bytes([PacketCode.Escape, PacketCode.Stop ^ 0xFF]))
return stopStuffed.replace(bytes([PacketCode.Start]), 
bytes([PacketCode.Escape, PacketCode.Start ^ 0xFF]))

This is the fastest. But I don't like the way the code reads and the 
intermediate sweeps.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Why doesn't Python include non-blocking keyboard input function?

2016-10-25 Thread Travis Griggs

> On Oct 25, 2016, at 5:55 AM, Chris Angelico  wrote:
> 
> On Tue, Oct 25, 2016 at 11:45 PM, Marko Rauhamaa  wrote:
>> Chris Angelico :
>> 
>>> On Tue, Oct 25, 2016 at 11:09 PM, Marko Rauhamaa  wrote:
 Blocking calls are evil.
>>> 
>>> Oh, that's why. Got it. So because blocking calls are fundamentally
>>> evil, we have to... what? What's so bad about them? Remember, not
>>> every program is a server handling myriad clients.
>> 
>> Myriads or not, we are talking about interactive (or reactive) programs.
>> The paradigm of choice is event-driven programming.
> 
> Have you watched "Tron"? A program goes to the I/O tower to receive a
> message from the User. It's an active operation on the part of the
> program. The user cannot initiate it, only the program can.
> 
> Tron is extremely accurate in this way.

Thanks for this ChrisA. Rest of this thread has been meh for me, but this one 
post, definitely won my MostValueablePost for the thread. :)

Still chuckling.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Why don't we call the for loop what it really is, a foreach loop?

2016-09-14 Thread Travis Griggs


> On Sep 13, 2016, at 13:57, rgrigo...@gmail.com wrote:
> 
> It would help newbies and prevent confusion.

for each in ['cake'] + ['eat', 'it'] * 2:
print(each)


-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Learning Python (or Haskell) makes you a worse programmer

2016-03-31 Thread Travis Griggs

> On Mar 30, 2016, at 2:36 PM, Gregory Ewing  
> wrote:
> 
> Tim Golden wrote:
> 
>> (I don't know how other English-speaking groups say the word, but in
>> England the first syllable is stressed and the second is the
>> conventional short "uh" sound).
> 
> I can attest that New Zealand follows the UK on this. I was
> surprised when I first heard an American pronounce it too.
> 
> The curious can hear the difference on these pages:
> 
> British:  http://www.oxforddictionaries.com/definition/english/python
> American: http://www.dictionary.com/browse/python?s=t

That does it. If I ever make some sort of open source module for pythun/pythawn 
I’ll be sure to call it either tuhmayto/tomawto. Or maybe I’ll call it 
puhtayto/potawto.

-- 
https://mail.python.org/mailman/listinfo/python-list


How to fix my imports/file structure

2016-01-20 Thread Travis Griggs
I wrote a simple set of python3 files for emulating a small set of mongodb 
features on a 32 bit platform. I fired up PyCharm and put together a directory 
that looked like:

minu/
client.py
database.py
collection.py
test_client.py
test_database.py
test_client.py

My imports are simple. For example, client.py has the following at the top:

from collection import Collection

Basically, client has a Client class, collection has a Collection class, and 
database has a Database class. Not too tough.

As long as I cd into the minu directory, I can fire up a python3 interpreter 
and do things like:

>>> from client import Client
>>> c = Client(pathstring='something’)

And everything just works. I can run the test_files as well, which use the same 
sorts of imports.

I'd like to modularize this, so I can use it another project by just dropping 
the minu directory alongside my application's .py files and just have 
everything work. E.g.

SomeDirectory/
application.py
minu/
…

and application.py does something like:

from minu.client import Client

When I try this though, and am running python3 from another directory, the 
local imports don't work. I placed an empty init.py in the minu directory. That 
made it so I could import minu. But the others broke. I tried using things like 

from .collection import Collection #added the dot

but then I can't run things in the original directory anymore, like I could 
before. What is the simple/right way to do this?

I have looked around a bit with Dr. Google, but none of the examples really 
clarify this well (at least, for me), feel free to point out the one I missed.
-- 
https://mail.python.org/mailman/listinfo/python-list


Confused by python-dbus weird behavior

2016-01-11 Thread Travis Griggs
This may not be a great list for this question (which would be?); it’s a big 
group, and I’m hoping there’s some people here that cross into these same areas.

I’m new to dbus, it seems it’s a sort of CORBA for the Linux world. :) Python 
seems to be a popular way to interact with it. I’m trying to interact with the 
BlueZ services for Bluetooth LE stuff, and the scant hints I can find seem to 
indicate dbus is the preferred way going forward. The BlueZ distribution even 
provides example code. That said, my question should be independent of whether 
this was BLE or a dbus interface for a Calculator program.

There is a class defined as such:

class Characteristic(dbus.service.Object):
def __init__(self, bus, index, uuid, flags, service):
# … set a bunch of attributes
dbus.service.Object.__init__(self, bus, self.path)

@dbus.service.method(GATT_CHRC_IFACE, in_signature='ay')
def WriteValue(self, value):
print('Default WriteValue called, returning error’)
raise NotSupportedException()

Then I have a subclass of my own:

class MyCharacteristic(Characteristic):
def __init__(self, bus, index, uuid, flags, service):
Characteristic.__init__(self, bus, index, uuid, flags, service)
# … set some of my own attributes

def WriteValue(self, value):
print(‘Got write value:’, value)
self.anotherMethod(value)
print(‘back from anotherMethod’)

def anotherMethod(self, value):
print(‘pondering this value:’, value)

My program does not call WriteValue directly. It seems to be called by the 
bluetooth machinery. The mainloop, or something like that. I don’t honestly 
know. I just know I use some other boilerplate code involving registration and 
the mainloop, to get it all running. And so the MyCharacteristic.WriteValue() 
method DOES get fired. I see the output. But when it gets to the anotherMethod 
call, it just seems to... not. More callbacks may fire later. But that’s the 
end of that one. I’ve tried this under python2 AND python3.

So my basic python-dbus question is: Is this some nuance where a callback 
method, inheriting from what looks like a proxy of some sort 
(dbus.service.Object) should/can not send messages to itself?

Help me python-obis, help me. You’re my only hope.


-- 
https://mail.python.org/mailman/listinfo/python-list


Re: When I need classes?

2016-01-11 Thread Travis Griggs

> On Jan 10, 2016, at 9:48 AM, Bernardo Sulzbach  
> wrote:
> 
> Essentially, classes (as modules) are used mainly for organizational purposes.
> 
> Although you can solve any problem you would solve using classes
> without classes, solutions to some big problems may be cheaper and
> more feasible using classes.

As a long term OO purist practitioner, I would add to this. Obviously, you can 
organize your code any way you want, with or without classes. You could put all 
your functions with an odd number of letters in one class, and all of the even 
numbered ones in another class. 

Having listened to the guy (Alan Kay) who coined the term (Object Oriented 
Programming) quite a bit over the years, I believe that the focus of OO (of 
which classes are a particular implementation approach) is to bind behavior to 
data. In “traditional” programming approaches, one focused on the algorithm 
(behavior) first, and then figured out what data needed to flow where to get 
the job done. Classes provided a mechanism to turn that equation, generally 
speaking, around. One thinks about the data first, and then figures out what 
behavior binds best to that data. And how that data will interact (inter-object 
behavior, often called messages) to get your job done. For some (many) 
problems, this can be a real win. And for some, not so much.

I think, this is often why, for a simple script, OO just kind of gets in the 
way. You have a straightforward procedure that you just want to do. The state 
(data) is not rich enough to make making it the focal point of your program.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Simplest/Idiomatic way to count files in a directory (using pathlib)

2015-06-22 Thread Travis Griggs
I should proof my posts before I send them, sorry

Subject nearly says it all.

If i’m using pathlib, what’s the simplest/idiomatic way to simply count how 
many files are in a given directory?

I was surprised (at first) when

   len(self.path.iterdir())

didn’t work.

I don’t see anything in the .stat() object that helps me.

I could of course do the 4 liner:

   count = 0
   for _ in self.path.iterdir():
   count += 1
   return count

The following seems to obtuse/clever for its own good:

   return sum(1 for _ in self.path.iterdir())
-- 
https://mail.python.org/mailman/listinfo/python-list


Simplest/Idiomatic way to count files in a directory (using pathlib)

2015-06-22 Thread Travis Griggs
Subject nearly says it all.

If i’m using pathlib, what’s the simplest/idiomatic way to simply count how 
many files are in a given directory?

I was surprised (at first) when

len(self.path.iterdir())

I don’t say anything on the in the .stat() object that helps me.

I could of course do the 4 liner:

count = 0
for _ in self.path.iterdir():
count += 1
return count

The following seems to obtuse/clever for its own good:

return sum(1 for _ in self.path.iterdir())
-- 
https://mail.python.org/mailman/listinfo/python-list


Concatenating Strings

2015-04-09 Thread Travis Griggs
I was doing some maintenance now on a script of mine… I noticed that I compose 
strings in this little 54 line file multipole times using the + operator. I was 
prototyping at the time I wrote it and it was quick and easy. I don’t really 
care for the way they read. Here’s 3 examples:

if k + ‘_@‘ in documents:

timeKey = k + ‘_@‘

historyKey = thingID + ‘_’ + k

I’m curious where others lean stylistically with this kind of thing. I see *at 
least* 2 other alternatives:

Use join():

if ‘’.join((k, ‘_@‘)) in documents:

timeKey = ‘’.join((k, ‘_@‘))

historyKey = ‘_’.join((thingID, k))

I don’t really like any of these. Maybe the 3rd, but I’d really rather see the 
pattern out. I also don’t like that I have to double the parens just to get a 
single arg joinable tuple for join()

Use format():

if ‘{}_@‘.format(k) in documents:

timeKey =  ‘{}_@‘.format(k)

historyKey = ‘{}_{}’.format(thingID, k)

I like these because you see a template of the values. But its still longer 
than just using +.

So I’m curious from those more seasoned, when they tend to use which 
approaches, and why.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: [SerialConnection] Help

2015-04-09 Thread Travis Griggs

 On Apr 7, 2015, at 8:42 AM, Hugo Caldas hcalda...@gmail.com wrote:
 
  read and write the port values with multi threading 

Care to elaborate what you mean by this part? In general, serial ports and 
multi threading don’t mix well. IOW, you’ll need to use multithreading pieces 
to make sure you serialize your access to your serial port.

As other have pointed out, pyserial is the package you want. Documentation is 
pretty good. We use it a lot. -- 
https://mail.python.org/mailman/listinfo/python-list


Re: MicroPython 1.4.1 released

2015-04-09 Thread Travis Griggs

 On Apr 4, 2015, at 4:43 PM, Damien George damien.p.geo...@gmail.com wrote:
 
 Hello everyone,
 
 We are pleased to announce the release of MicroPython version 1.4.1!
 
 MicroPython is an implementation of Python 3.4 which is optimised for
 systems with minimal resources, including microcontrollers.
 
 Since our last announcement, this release is both more micro and
 more Python.
 
 Code size of the bare Thumb2 architecture version has dropped to under
 71k (without reduction of features), the RAM usage has been further
 optimised, and support for 16-bit microcontrollers has been proven via
 the port to a PIC microcontroller with just 8k RAM.
 
 On the Python side of things, there is now a stackless mode with
 both strict and non-strict behaviour.  Strict will always use the heap
 to allocate a call frame, where non-strict will fall back to the C
 stack if the heap is exhausted.  More special methods have been
 implemented, along with proper descriptors, OrderedDict class, basic
 frozen module support and the ability to override builtins, among
 other things.
 
 The test suite has grown and coverage of the code is now beyond 91%.
 
 Many other features have been implemented for the ports to various
 microcontroller platforms, bugs have been fixed and the docs have been
 improved.  A full change log is available at
 https://micropython.org/resources/micropython-ChangeLog.txt .
 
 For more information about the project please visit
 http://micropython.org/
 https://github.com/micropython/micropython

This is cool. I’m glad you guys are doing this and glad you are seeing some 
promise and success. I’ve enjoyed reading your updates, especially the 
technical ones. I wish you’d do one on whatever you’re doing for memory 
management in your particular python variant. GC in a tightly constrained 
environment is interesting.

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Newbie looking for elegant solution

2015-03-25 Thread Travis Griggs

 On Mar 24, 2015, at 8:28 PM, Chris Angelico ros...@gmail.com wrote:
 
 On Wed, Mar 25, 2015 at 2:13 PM,  otaksoftspamt...@gmail.com wrote:
 I have a list containing 9600 integer elements - each integer is either 0 or 
 1.
 
 Starting at the front of the list, I need to combine 8 list elements into 1 
 by treating them as if they were bits of one byte with 1 and 0 denoting bit 
 on/off (the 8th element would be the rightmost bit of the first byte).
 
 Speed is not of utmost importance - an elegant solution is. Any suggestions?
 
 Oooh fun!
 
 l = [1, 0, 1, 1, 0, 0, 0, 1, 0, 1, 1, 0, 1, 0, 0, 1, 0, 1, 1, 1, 0, 1, 0, 
 1]
 list(int(''.join(str(i) for i in l),2).to_bytes(len(l)//8,'big'))
 [177, 105, 117]
 
 Convert it into a string, convert the string to an integer
 (interpreting it as binary), then convert the integer into a series of
 bytes, and interpret those bytes as a list of integers.
 
 Example works in Python 3. For Python 2, you'll need ord() to get the
 integers at the end.
 
 I'm not sure how elegant this is, but it's a fun trick to play with :)
 
 Next idea please! I love these kinds of threads.

Me too. These are my favorite threads. Here’s my entry:

[sum(b  (7 - i) for i, b in enumerate(bits)) for bits in zip(*[l[n::8] for n 
in range(8)])]

I think there has to be a better way to do the left hand part, but I liked the 
zipped iterators on 8 slices.

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python Worst Practices

2015-03-02 Thread Travis Griggs

 On Mar 1, 2015, at 5:53 PM, Dennis Lee Bieber wlfr...@ix.netcom.com wrote:
 
 On Sun, 1 Mar 2015 20:16:26 + (UTC), alister
 alister.nospam.w...@ntlworld.com declaimed the following:
 
 
 The language is called English, the clue is in the name. interestingly 
 most 'Brits' can switch between American English  English without too 
 much trouble (I still have a problem with Chips) 
 
   Okay... Is that a reference to (US) Fries, or US usage reference to
 (UK) Crisps.
 
   Might as well add the confusion of biscuit  cookie (my biscuits look
 like your scones)... And lets not bring up the subject of suspenders...
 Bonnets, boots, and lifts.
 
   A pub's a bar; a bar's a gate; a gate's a street

Reminds me of Richard Lederer’s writings. 

http://www.etni.org.il/farside/crazyenglish.htm

Whether or not Brits should sprinkle the letter ‘u’ around for some extra 
spice, seems like the very smallest of our worries.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Pyston 0.3 self-hosting

2015-02-27 Thread Travis Griggs

 On Feb 24, 2015, at 9:47 PM, Steven D'Aprano 
 steve+comp.lang.pyt...@pearwood.info wrote:
 
 Pyston 0.3, the latest version of a new high-performance Python 
 implementation, has reached self-hosting sufficiency:
 
 
 http://blog.pyston.org/2015/02/24/pyston-0-3-self-hosting-sufficiency/
 

Does it do python3.4 yet?
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python Worst Practices

2015-02-27 Thread Travis Griggs

 On Feb 25, 2015, at 12:45 PM, Mark Lawrence breamore...@yahoo.co.uk wrote:
 
 http://www.slideshare.net/pydanny/python-worst-practices
 
 Any that should be added to this list?  Any that be removed as not that bad?

I read ‘em. I thought they were pretty good, some more than others. And I 
learned some things. I especially liked the first one, since I’ve struggled 
with that one a bunch. In the context of “hey, accept Python for what it is”, I 
agree greatly with it. Memorize the builtins, and stay the heck away from them. 
I’ve been burned many times because I stored some bytes in a binding call, er, 
uh, ‘bytes’. And having mentored some people learning Python in the early 
stages, any explanation other than “Thou Shalt Never Use These Holy Words” just 
confuses people.

That said… 

If I were giving a talk at SPLASH (or some other suitable polyglot conference), 
I might do one called “Language Design Worst Practices”.

One of my first slides might be titled:

Abuse Common Tokens in Confusing Ways

* Make your language have a lot of keywords. Enough to make memorizing them ALL 
unlikely, requiring constant visits to your documentation
* Make sure said keywords are many of the obvious words programmers would use 
in their applications (map, object, bytes, dir, etc)
* Design your syntax so that you can’t disambiguate them contextually between 
bind and reference
* Be sure to use it in a late bound language where no warnings will be provided 
about the mistake you’re making at authorship time, deferring the educational 
experience to sundry run times

In my examples column of this bad practice, I’d put Python of course. :)

I do like Python, and I accept it for what it is, so no one needs to jump 
forward as a Holy Python See to convert me to the truth. I also know that with 
most other languages, that first slide wouldn’t need to be one of the prominent 
“worst practices” slide.
-- 
https://mail.python.org/mailman/listinfo/python-list


pymongo and attribute dictionaries

2015-02-04 Thread Travis Griggs
I really like pymongo. And I really like Python. But one thing my fingers 
really get tired of typing is

someDoc[‘_’id’]

This just does not roll of the fingers well. Too many “reach for modifier keys” 
in a row. I would rather use

someDoc._id

Googling shows that I’m not the first to want to do this in the general sense 
(e.g. 
http://stackoverflow.com/questions/4984647/accessing-dict-keys-like-an-attribute-in-python).

Arguments aside of whether this should or shouldn’t be done, I want to know how 
I might solve this with Python. Consider it an academic pursuit.

The problem I have is not how to do the AttributeDictionary subclass, there are 
plenty of those examples. The problem is that the pymongo APIs already return 
dictionaries. In a language (Smalltalk, Objective-C, Ruby) that supports class 
extensions, that would be my first tool of choice to solve this problem. I’d 
just extend Dictionary to behave the way I want and be done with it. I can’t do 
that in Python though. I guess I could make my own module that subclasses the 
relevant pymongo classes, and do super() calling implementations of all of the 
relevant methods, coercing the return type. That is a maintenance headache 
though.

What are my options, if any?
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: pymongo and attribute dictionaries

2015-02-04 Thread Travis Griggs

 On Feb 4, 2015, at 9:22 AM, Ian Kelly ian.g.ke...@gmail.com wrote:
 
 On Wed, Feb 4, 2015 at 9:50 AM, Travis Griggs travisgri...@gmail.com wrote:
 I really like pymongo. And I really like Python. But one thing my fingers 
 really get tired of typing is
 
 someDoc[‘_’id’]
 
 This just does not roll of the fingers well. Too many “reach for modifier 
 keys” in a row. I would rather use
 
 someDoc._id
 
 Googling shows that I’m not the first to want to do this in the general 
 sense (e.g. 
 http://stackoverflow.com/questions/4984647/accessing-dict-keys-like-an-attribute-in-python).
 
 Arguments aside of whether this should or shouldn’t be done, I want to know 
 how I might solve this with Python. Consider it an academic pursuit.
 
 The problem I have is not how to do the AttributeDictionary subclass, there 
 are plenty of those examples. The problem is that the pymongo APIs already 
 return dictionaries. In a language (Smalltalk, Objective-C, Ruby) that 
 supports class extensions, that would be my first tool of choice to solve 
 this problem. I’d just extend Dictionary to behave the way I want and be 
 done with it. I can’t do that in Python though. I guess I could make my own 
 module that subclasses the relevant pymongo classes, and do super() calling 
 implementations of all of the relevant methods, coercing the return type. 
 That is a maintenance headache though.
 
 What are my options, if any?
 
 You could construct the AttributeDictionary by copying the dict
 returned from pymongo. The question then is whether the copying would
 be too expensive or not.
 
 Alternately, you could just wrap the dictionaries returned by pymongo
 in an object. Something like this should be all you need:
 
 class AttrDictWrapper(object):
def __init__(self, the_dict):
self.__dict__ = the_dict
 
 d = AttrDictWrapper({'spam': 42, 'ham': False})
 d.spam
 42
 d.ham
 False
 

Yes, that is clever. So if you wanted to minimize the amount of typing you had 
to do at all of your pymongo API call sites, what strategy would you use to 
keep that relatively terse?

Is the following the right approach to take?

class Doc(object):
def __init__(self, target):
self.__dict__ = target

and then something like

for doc in client.db.radios.find({’_id': {’$regex’: ‘^[ABC]'}}):
pprint(doc)

changes to

for doc in ((Doc(d) for d in client.db.radios.find({’_id': {’$regex’: 
‘^[ABC]'}})):
pprint(doc)

Are there other approaches? Feel free to impress me with evil abuses in the 
interest of academic enrichment...

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Cairo module

2015-02-03 Thread Travis Griggs

 On Feb 3, 2015, at 1:00 PM, Poul Riis prii...@gmail.com wrote:
 
 I just tried the Cairo Python module.
 I ran the test file below.
 It works perfectly but instead of saving the resulting image as a file I want 
 to see it displayed directly on the screen.
 How can I do that?
 

I have quiet a bit of experience with Cairo (I wrote language bindings for it 
in Smalltalk and had the time of my life with it there); I have no experience 
with the pycairo bindings.

 
 import math
 import cairo
 
 WIDTH, HEIGHT = 256, 256
 
 surface = cairo.ImageSurface (cairo.FORMAT_ARGB32, WIDTH, HEIGHT)

This is your basic problem right here. And ImageSurface is for creating an 
Image (sometimes called a raster graphic or bitmap). If you want to display 
directly to your screen, you need to create a surface that binds to your 
screen’s display functionality. There is one for each main operating system:

Win32Surface
XLibSurface
QuartzSurface (I see that this is missing from the pycairo documentation, but 
it is in the cairo documentation, and the pycairo.c file at least has some 
reference to it)

Allocating one of these involves getting handles (and other information) for a 
given window on screen of your host OS and creating the surface from it.


 ctx = cairo.Context (surface)
 
 ctx.scale (WIDTH, HEIGHT) # Normalizing the canvas
 
 pat = cairo.LinearGradient (0.0, 0.0, 0.0, 1.0)
 pat.add_color_stop_rgba (1, 0.7, 0, 0, 0.5) # First stop, 50% opacity
 pat.add_color_stop_rgba (0, 0.9, 0.7, 0.2, 1) # Last stop, 100% opacity
 
 ctx.rectangle (0, 0, 1, 1) # Rectangle(x0, y0, x1, y1)
 ctx.set_source (pat)
 ctx.fill ()
 
 ctx.translate (0.1, 0.1) # Changing the current transformation matrix
 
 ctx.move_to (0, 0)
 ctx.arc (0.2, 0.1, 0.1, -math.pi/2, 0) # Arc(cx, cy, radius, start_angle, 
 stop_angle)
 ctx.line_to (0.5, 0.1) # Line to (x,y)
 ctx.curve_to (0.5, 0.2, 0.5, 0.4, 0.2, 0.8) # Curve(x1, y1, x2, y2, x3, y3)
 ctx.close_path ()
 
 ctx.set_source_rgb (0.3, 0.2, 0.5) # Solid color
 ctx.set_line_width (0.02)
 ctx.stroke ()
 
 surface.write_to_png (example.png) # Output to PNG 
 -- 
 https://mail.python.org/mailman/listinfo/python-list

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Is there a cairo like surface for the screen without the window hassle

2015-02-03 Thread Travis Griggs

 On Feb 2, 2015, at 5:20 AM, Antoon Pardon antoon.par...@rece.vub.ac.be 
 wrote:
 
 I need to have a program construct a number of designs. Of course I can 
 directly
 use a pfd surface and later use a pdf viewer to check. But that becomes rather
 cumbersome fast. But if I use a cairo-surface for on the screen I suddenly 
 have
 to cope with expose events and all such things I am not really interested in.
 
 So does someone know of a package that provides a cairo like surface but that
 would take care of the events in a rather straight forward matter, so that my
 program could make it's design in a window on the screen just as if it is
 designing it in a pdf file.
 

For the most part, you cannot draw directly to the screen with Cairo. Some OSes 
kind of allow out, but they won’t repaint it for you. Any viewing software that 
will auto detect file updates and reload would do the trick. For example, I 
know that preview on OS X will automatically reload a png file that I write. 
Cairo can generate png output. Just open preview on the file, and then have the 
program rewrite the same file.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: FYI: Micro Python running on kickstarter pyBoard project, now shipping

2014-10-23 Thread Travis Griggs

 On Oct 23, 2014, at 2:11 PM, sohcahto...@gmail.com wrote:
 
 On Thursday, October 23, 2014 10:07:26 AM UTC-7, jkn wrote:
 Hi all
I haven't heard in mentioned here, but since I saw one of the boards 
 today thought I'd pass on the news:
 
 The Kickstarter 'MicroPython' project, which has a tiny 'pyboard' (only a 
 couple of sq.inches in size) with a processor running 'a complete re-write 
 of the Python (version 3.4) programming language so that it fits and runs on 
 a microcontroller' is now shipping.
 
https://micropython.org/
 
 Looks nice; I have no connection but will be getting one myself to play 
 with...
 
Cheers
J^n
 
 
 Is there any particular reason to get one of these when I can get a Raspberry 
 Pi which is faster, has more memory, and a bundle of other features?
 
 I mean, the idea seems cool and all, but I'm trying to understand why I would 
 want to spend the ~$45 on something like that when a ~$35 Raspberry Pi will 
 do everything and more, and do it faster.

Power Consumption.

I don’t know (looked quick, but didn’t find anything fast enough) the exact 
numbers, but the Pi is meant to be plugged in to something, or chew through 
batteries quickly. If your IoT device fits in that space and you need all that 
periphery, that’s great. The Pyboard is running a STM32F405RG (low power contex 
M4). So I’m betting various children of mine, that it can go a whole lot longer 
on the same bit of power. Coin cell operation for long periods is probable.

I think you look at the $45 as a development board. The site says you can get 
access to just about everything, so there’s nothing to keep you from 
prototyping your killer pythonic IoT gadget with these, then doing your own 
tiny board, populating them with the same chip that you can get from DigiKey 
for $7 a piece in quantity. Can’t really do that with the Pi.

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Toggle

2014-10-08 Thread Travis Griggs

On Oct 8, 2014, at 9:57 PM, Gregory Ewing greg.ew...@canterbury.ac.nz wrote:

 Seymore4Head wrote:
 I want to toggle between color=Red and color=Blue


Don’t forget polymorphic dispatch…

class Red(object):
def toggle(self):
return Blue()

class Blue(object):
def toggle(self):
return Red()


Blue().toggle().toggle().toggle().toggle().toggle() :)

--
Travis Griggs
Objologist
Some of them wanted to sell me snake oil and I'm not necessarily going to 
dismiss all of these, as I have never found a rusty snake. --Terry Pratchett

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How to show a dictionary sorted on a value within its data?

2014-10-01 Thread Travis Griggs


Sent from my iPhone

 On Oct 1, 2014, at 04:12, Peter Otten __pete...@web.de wrote:
 
 `lambda` is just a fancy way to define a function inline

Not sure fancy is the correct adjective; more like syntactic tartness (a less 
sweet version of syntactic sugar).

:)
-- 
https://mail.python.org/mailman/listinfo/python-list


Python stdout goes where under systemd? (Was: Example of python service running under systemd?)

2014-09-12 Thread Travis Griggs
Thanks all for the help/advice. I’m getting there.

To experiment/learn, I made a simple python program (/Foo/cyclic.py):
 
#!/usr/bin/env python3

import time

while True:
time.sleep(5)   
with open('sound', 'r') as file:
currentValue = file.read()
otherValue = 'tick' if currentValue == 'tock' else 'tock'
with open('sound', 'w') as file:
file.write(otherValue)
print(currentValue, '-', otherValue)

Run from the command line, this tick-tocks nicely, both outputting, as well as 
updating the ‘/Foo/sound’ file on a 5 second period.

I then created a simple .service file:

[Unit]
Description=Foo for learning service
After=network-online.target

[Service]
Type=simple
ExecStart=/Foo/cyclic.py
WorkingDirectory=/Foo
StandardOutput=journal

[Install]
WantedBy=multi-user.target

I chose to be “explicit” with some of the default options (Type and 
StandardOutput).
I finally executed:

systemctl --system daemon-reload
systemctl enable foo
systemctl start foo

It seems to work. Almost. The file is being updated regularly (watch cat 
/Foo/sound shows the change happening). But I can’t seem to find the output 
from my print() statement. journalctl -f doesn’t show anything. Nor does tail 
-f /var/log/syslog or any of the others. It just seems to be going nowhere? Is 
there something I need to do special to get the print() output going somewhere 
logable?

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python stdout goes where under systemd? (Was: Example of python service running under systemd?)

2014-09-12 Thread Travis Griggs

On Sep 12, 2014, at 12:05 PM, Travis Griggs travisgri...@gmail.com wrote:

 Thanks all for the help/advice. I’m getting there.
 
 To experiment/learn, I made a simple python program (/Foo/cyclic.py):
 
#!/usr/bin/env python3
 
import time
 
while True:
time.sleep(5)  
with open('sound', 'r') as file:
currentValue = file.read()
otherValue = 'tick' if currentValue == 'tock' else 'tock'
with open('sound', 'w') as file:
file.write(otherValue)
print(currentValue, '-', otherValue)
 
 Run from the command line, this tick-tocks nicely, both outputting, as well 
 as updating the ‘/Foo/sound’ file on a 5 second period.
 
 I then created a simple .service file:
 
[Unit]
Description=Foo for learning service
After=network-online.target
 
[Service]
Type=simple
ExecStart=/Foo/cyclic.py
WorkingDirectory=/Foo
StandardOutput=journal
 
[Install]
WantedBy=multi-user.target
 
 I chose to be “explicit” with some of the default options (Type and 
 StandardOutput).
 I finally executed:
 
systemctl --system daemon-reload
systemctl enable foo
systemctl start foo
 
 It seems to work. Almost. The file is being updated regularly (watch cat 
 /Foo/sound shows the change happening). But I can’t seem to find the output 
 from my print() statement. journalctl -f doesn’t show anything. Nor does tail 
 -f /var/log/syslog or any of the others. It just seems to be going nowhere? 
 Is there something I need to do special to get the print() output going 
 somewhere logable?
 

Arghhh… I’ll answer my own question here. I wasn’t patient enough, when I 
checked after lunch, I found I had a mountain of tick/tock entries in 
journalctl -f. Python print() is buffered, so it wasn’t showing up except in 
huge blocks. Changed the .service file to start with -u and everything works as 
expected now.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Newer Debian versions of python on older Debian distros?

2014-09-11 Thread Travis Griggs
On Sep 8, 2014, at 5:06 PM, Chris Angelico ros...@gmail.com wrote:

 Alternatively, you could just run Debian Jessie. I have a few Jessie
 systems on the network, with a Python 3.4 IIRC, and there've been no
 stability problems lately. Both options are pretty easy.

In the end, we were able to get jessie running on this little board (it’s an 
Atmel Xplained SAMA5D3 which boasts one of the lowest linux power 
consumptions). And that solved our problems.
-- 
https://mail.python.org/mailman/listinfo/python-list


Example of python service running under systemd?

2014-09-11 Thread Travis Griggs
I’ve been reading lots of systemd docs. And blogs. Etc. At this point, I think 
I would benefit from learning by example…

Does anyone have an example .service file that they use to launch a long 
running service written as a python program?

If there is any example of what you changed to your python program itself, that 
to would be really instructional for me.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Example of python service running under systemd?

2014-09-11 Thread Travis Griggs

On Sep 11, 2014, at 11:18 AM, Chris “Kwpolska” Warrick kwpol...@gmail.com 
wrote:

 Depends what you want. 

Mine is not a web service. My main.py looks like this:

#!/usr/bin/env python3

import cycle
import pushTelemetry
from threading import Thread

def main():
Thread(target=pushTelemetry.udpLoop).start()
Thread(target=cycle.cycleLoop).start()

if __name__ == '__main__':
main()

It basically creates two threads, one which does some local processing and 
control, the other which periodically does reporting via udp packets. I use the 
dual threads because they both work with a shared serial port at times, so I 
have to synchronize access through that.

What I want is to have this startup, after my board has it’s networking layer 
up and running (and hopefully a valid ip address by then), and to just keep 
running forever
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Example of python service running under systemd?

2014-09-11 Thread Travis Griggs

On Sep 11, 2014, at 2:29 PM, Ervin Hegedüs airw...@gmail.com wrote:

 Hi Travis,
 
 On Thu, Sep 11, 2014 at 02:06:48PM -0700, Travis Griggs wrote:
 
 On Sep 11, 2014, at 11:18 AM, Chris “Kwpolska” Warrick kwpol...@gmail.com 
 wrote:
 
 Depends what you want. 
 
 Mine is not a web service. My main.py looks like this:
 
 #!/usr/bin/env python3
 
 import cycle
 import pushTelemetry
 from threading import Thread
 
 def main():
Thread(target=pushTelemetry.udpLoop).start()
Thread(target=cycle.cycleLoop).start()
 
 if __name__ == '__main__':
main()
 
 It basically creates two threads, one which does some local processing and 
 control, the other which periodically does reporting via udp packets. I use 
 the dual threads because they both work with a shared serial port at times, 
 so I have to synchronize access through that.
 
 What I want is to have this startup, after my board has it’s networking 
 layer up and running (and hopefully a valid ip address by then), and to just 
 keep running forever
 
 may be you think about the fork(), eg:
 
 if __name__ == __main__:
...other codes, eg. drop root privileges, ...
...check arguments...
try:
  pid = os.fork()
  if pid  0:
  #print Daemon started (pid: %d) % (pid)
  sys.exit(0)
except OSError, e:
  print sys.stderr, fork #1 failed: %d (%s) % (e.errno, e.strerror)
  sys.exit(1)
 
os.chdir(/)
os.setsid()
os.umask(0)
 
# do second fork
try:
  pid = os.fork()
  if pid  0:
  #print Daemon started (pid: %d) % (pid)
  sys.exit(0)
except OSError, e:
  print sys.stderr, fork #2 failed: %d (%s) % (e.errno, e.strerror)
  sys.exit(1)
 
main()

OK, I’m probably going to show my naivety about something simple here…

I thought a “fork” essentially created a memory copy of the original process 
and let it go off running. The problem is, in the bowels of the code executing 
in those loops, I access a single instance of a threading.RLock, so that I can 
avoid both threads trying to do transactions with a single serial port at the 
same time. If I end up with two copies of the base process, unhooked from their 
parent, does that RLock still remain valid between the two? I thought since 
they were complete different copies of the same memory, they would no longer be 
coordinated.

Is this a day where I discover something new?
-- 
https://mail.python.org/mailman/listinfo/python-list


Newer Debian versions of python on older Debian distros?

2014-09-08 Thread Travis Griggs
(I realize that this may be seen as off topic for as a general python question, 
but given my historical experience with the Debian community’s predilection to 
answer all questions with a grumpy “go read the very very very very large and 
ever shifting fine manual”, I’m hoping for better luck here.)

Does anyone have experience with using newer versions of python debian packages 
(in particular, python3 and python3-bson-ext from ‘testing’) on older stable 
versions (‘wheezy’ in this case)? If someone’s figured out how to do this 
easily, I’d love to hear the recipe!

TIA


-- 
https://mail.python.org/mailman/listinfo/python-list


Halfway point between interactive and daemon?

2014-08-22 Thread Travis Griggs
I have a python3 program that performs a long running service on a semi 
embedded linux device. I've been in the prototyping stage.  I just run it from 
the command line and use print() statements to let me know the thing is making 
acceptable process.

At some point, I need to properly daemonize it. Write an init script, find a 
logging framework/module, batton all the hatches down, so to speak.

I’m curious if there’s a technique one could use to get half way there. 
Basically, with minimal modifications, I’d like to get it running at startup. 
So I can put a line like this in rc.local

nohup python3 myMain.py 21  /var/log/mylog.log 

Then I can “check” on it when I need to with a tail -f /var/log/mylog.log. But 
then I have the problem of managing the log size. And also I either have to 
wait for stdout to flush, or insert sys.stdout.flush() after any of my 
print()’s.

I haven’t done a lot of these daemon processes (and this is my first with 
python), so I was curious what those with experience do here.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: proposed syntax for multiline anony-functions (hopefully?)

2014-08-22 Thread Travis Griggs

On Aug 21, 2014, at 12:55 AM, icefap...@gmail.com wrote:

 Hi, just wanting to do a shot in the dark,but maybe this syntax is Pythonic 
 (in a we-are-all-grown-ups fashion, ahem)enough to get its way into the 
 language
 this is what yours truly thinks: don't we all know that : means the next 
 token must be an indent (mostly)? and doesn't the ( and its alikes, [ and } 
 begin an space-insensitive lexing context? so all we need is having an 
 space-sensitivity-stack and the corresponding ( counting stack and this 
 way we could match opening and closing () and pop the 
 space-sensitivity-stack whenever the ( counting stack gets a 0 at the top:
snip

Those more pythonista than me have weighed in on the particulars. I’ll offer 
some more general thoughts.

While I dwell in the land of pythonistas, I’m a an expat from the Island of 
Smalltalk. I live happily in Pythonville and will probably never return to the 
shrinking island, I do miss Smalltalk’s block closures. I don’t miss them *too* 
much, because things like comprehensions as well as the large library of 
functional like modules, covers many of the use cases. But I do miss their 
simple elegance.

I do not like the python lambda. For two reasons.

One: In a language that sought to be approachable by simple people (i.e. non 
computer science graduates who would use it in addition to their 
scientific/education background), I can’t believe they threw in a 6 character  
phonetic description of a greek character to imply “fragment of code expression 
to be executed in a removed context”. Show a subset of keyword.kwlist to a 
non-comp-sci guy and tell me if when they see the ‘lambda’ betwixt the others, 
they don’t stop and think “huh, one of these is not like the others”.

Two: The reason that this subject circles regularity, because they used a 
keyword, it can only be used as a literal creator for a single line expression. 
So we keep coming back to “how can we do multiple expressions with a 
lambda/closure”.

For the unaware, the Smaltalk syntax for a literal block closure was a pair of 
[ ]. First of all, I liked that the characters actually looked like a “block” 
with the corners. I liked that it did not use parentheses. Parentheses are 
pretty loaded already, and it helped the brain pick out the differences 
instantly. I don’t like the OP’s proposal because I don’t think (def()) is 
distinct from normal grouping () statements. And I liked how terse they are. 
Two characters and you had a block. They are *everywhere* in the library. 
Compare that with how often you find ‘lambda’ in the python standard modules. I 
used to joke about the irony, that no language did more with functional 
closures than the all-objects-all-the-time Smalltalk, and that CLOS had a more 
robust object model than Smalltalk.

To me, for a multiple-expression (multi line or not) literal closure syntax to 
succeed, it must a) denote both the start and stop (not a leading keyword), b) 
be extremely terse so that the cost of creating closures is reduced c) not be 
confused with other common literal denotation so it can be quickly recognized 
when reading close (so [ and { are out for example, because of lists and 
dictionaries, and using   would cause complete confusion because it’s hard at 
a glance to differentiate from a comparison operand).

Personally, I don’t think the desire to use lines as statement boundaries 
(something I like a lot) and at the same time to tersely pack multiple 
statements into a deferred code fragment, are reconcilable. And I don’t think 
there’s critical mass desire for them. So this subject will continue to 
resurface regularly. But I thought I’d chime in with a “foreigners” perspective.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: TypeError: 'bytes' object is not callable error while trying to converting to bytes.

2014-08-05 Thread Travis Griggs


 On Aug 4, 2014, at 22:57, Chris Angelico ros...@gmail.com wrote:
 
 On Tue, Aug 5, 2014 at 3:47 PM, Satish ML satishmlwiz...@gmail.com wrote:
 bytes = file.read()
 
 You've just shadowed the built-in type 'bytes' with your own 'bytes'.
 Pick a different name for this, and you'll be fine. 'data' would work.

Until python4 introduces the 'data' built in. :)
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: PEP8 and 4 spaces

2014-07-05 Thread Travis Griggs

 On Jul 4, 2014, at 11:29, Lie Ryan lie.1...@gmail.com wrote:
 
 On 04/07/14 07:55, Gregory Ewing wrote:
 Steven D'Aprano wrote:
 
 That's exactly the problem with tabs - whatever you think your code
 looks like with tabs, other people will see quite different picture.
 
 Why do you consider this a problem?
 
 It's a problem if you try to use tabs for lining things
 up in a tabular fashion in your source code.
 
 The solution is not to use tabs for that -- only use
 tabs for indentation, and use spaces for everything
 else. Or, as PEP 8 suggests, don't try to line things
 up in the first place.
 
 PEP8 suggests using this style of method invocation:
 
obj.method(foo,
   bar,
   baz)
 
 which is an effect impossible to do correctly with tabs alone. If you want to 
 follow this style strictly, you end up having to either mix tabs and spaces, 
 or just use spaces, or as I prefer it, avoid the issue altogether:
 
obj.method(
foo,
bar,
baz,
)

Ok, here's irony. I'm looking at that thinking what the heck is he talking 
about?!?. And then my brain catches up. My mail reader is of course modern 
and does not use a mono space font. So the value of the along ed indent is lost 
anyway. But wasn't that what spaces were supposed to give us over tabs, some 
separation from the trading betwixt different editors? Chuckle.

Travis Griggs

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: OT: This Swift thing

2014-06-06 Thread Travis Griggs


 On Jun 5, 2014, at 1:14, Alain Ketterlin al...@dpt-info.u-strasbg.fr wrote:
 
 Swift's memory management is similar to python's (ref. counting). Which
 makes me think that a subset of python with the same type safety would
 be an instant success.

Except that while you don't need to regularly worry about cycles in python, you 
do in swift. Which means you get to think constantly about direct and indirect 
cycles, figure out where to put weak stuff, when to use a local to keep a weak 
property alive until it finds it's strong home, etc.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Micro Python -- a lean and efficient implementation of Python 3

2014-06-06 Thread Travis Griggs

On Jun 4, 2014, at 4:01 AM, Tim Chase python.l...@tim.thechases.com wrote:

 If you use UTF-8 for everything

It seems to me, that increasingly other libraries (C, etc), use utf8 as the 
preferred string interchange format. It’s universal, not prone to endian 
issues, etc. So one *advantage* you gain for using utf8 internally, is any time 
you need to hand a string to an external thing, it’s just ready. An app that 
reserves its internal string processing to streaming based ones but has to to 
hand strings to external libraries a lot (e.g. cairo) might actually benefit 
using utf8 internally, because a) it’s not doing the linear search for the odd 
character address and b) it no longer needs to decode/encode every time it 
sends or receives a string to an external library.

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: IDE for python

2014-05-29 Thread Travis Griggs


 On May 28, 2014, at 3:43, Sameer Rathoud sameer.rath...@gmail.com wrote:
 
 Hello everyone,
 
 I am new to python.
 
 I am currently using python 3.3
 
 With python I got IDLE, but I am not very comfortable with this.
 
 Please suggest, if we have any free ide for python development.
 -- 
 https://mail.python.org/mailman/listinfo/python-list

I use either vim or textwrangler for simple one file scripts. For larger things 
with multiple files and/or classes, I like pycharm best ( free community 
edition ). I tried both pydev and wing before that.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How keep Python 3 moving forward

2014-05-24 Thread Travis Griggs


Sent from my iPhone

 On May 24, 2014, at 7:35, blindanagram no...@nowhere.net wrote:
 
 On 24/05/2014 08:13, wxjmfa...@gmail.com wrote:
 Le vendredi 23 mai 2014 22:16:10 UTC+2, Mark Lawrence a écrit :
 An article by Brett Cannon that I thought might be of interest 
 
 http://nothingbutsnark.svbtle.com/my-view-on-the-current-state-of-python-3
 
 
 
 -- 
 
 My fellow Pythonistas, ask not what our language can do for you, ask 
 
 what you can do for our language.
 
 
 
 Mark Lawrence
 
 
 
 ---
 
 This email is free from viruses and malware because avast! Antivirus 
 protection is active.
 
 http://www.avast.com
 
 =
 =
 
 Quote:
  And with Python 3.4 I really have not heard anyone complain that they 
 wouldn't like to use Python 3 instead of Python 2. 
 
 Or the devs do not wish to listen.
 
 Python 3 will never work.
 
 It works for me.

Works for me too. I do python3 exclusively. If the library/tool I need is 
python 2 only, I figure it's obvious it's in maintenance mode only and find 
something else.
-- 
https://mail.python.org/mailman/listinfo/python-list


Why does isoformat() optionally not print the fractional seconds?

2014-04-22 Thread Travis Griggs
Python(3) let me down today. Better to be explicit, and all that, didn’t pan 
out for me.

I have time series data being recorded in a mongo database (I love pymongo). I 
have an iOS app that consumes the data. Since JSON doesn’t have a time format, 
I have to stringify the times when transmitting between the two. To parse it on 
the obj-c side, I use 

NSDateFormatter *parser = [NSDateFormatter new];
parser = [NSTimeZone timeZoneWithAbbreviation:@GMT];
[parser setDateFormat:@-MM-dd'T'HH:mm:ss.S”];
NSDate *date = [parser dateFromString: thatJsonString];

Which was working swimmingly, until I started getting occasional and infrequent 
nil dates at times. I thought I had a storage issue or something with my REST 
api, or the server, or something. But it was simply now and then again, why 
1000’s of data points, I managed to get 0 milliseconds from time to time, which 
resulted in the isoformat() I was using to suddenly leave off the .S part of 
the string. And since the parse then failed, the iOS side decided it wasn’t 
valid and returned a nil.

Haven’t decided where/how I’ll work around it yet, but the isoformat() seemed 
unpythonic to me today.

Thanks for hearing me whine.

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: test

2014-03-15 Thread Travis Griggs


 On Mar 15, 2014, at 14:24, Mark H Harris harrismh...@gmail.com wrote:
 
 test

Pass
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Functions help

2014-02-23 Thread Travis Griggs


 On Feb 23, 2014, at 17:09, Mark Lawrence breamore...@yahoo.co.uk wrote:
 
 For the benefit of newbies, besides the obvious indentation error above, the 
 underscore basically acts as a dummy variable.  I'll let the language lawyers 
 give a very detailed, precise description :)

You mean a dummy name binding, right? If we say variable we might confuse 
those newly arrived pilgrims from other language kingdom.



(If you squint hard, I think there's some facetious tags in there :) )
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Remove comma from tuples in python.

2014-02-21 Thread Travis Griggs

On Feb 21, 2014, at 6:32 AM, Roy Smith r...@panix.com wrote:

 In article mailman.7230.1392992078.18130.python-l...@python.org,
 Peter Otten __pete...@web.de wrote:
 
 
 [x*x for (x,) in lst]
 
 [paraphrasing...] can be better written as:
 
 [x*x for [x] in items]
 
 I'm torn between, Yes, the second form is distinctly easier to read 
 and, If you think the second form is easier to read, you're admitting 
 you're not really fluent in Python”.

I’ve used the comma form with struct.unpack() frequently:

count, = struct.unpack(‘!I’, self.packet)

That’s after I don’t use it and end up scratching my head for a while and 
finally remember that unpack returns a tuple regardless of how many things I 
unpack from it. It’s just natural if you’re doing lots of single unpacks to 
think it returns a single value. Either way, I much prefer it to:

count = struct.unpack(‘!I’, self.packet)[0]
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Can global variable be passed into Python function?

2014-02-21 Thread Travis Griggs
On Feb 21, 2014, at 4:13 AM, Ned Batchelder n...@nedbatchelder.com wrote:

 Man, do I hate this idea that Python has no variables.  It has variables 
 (names associated with values, and the values can change over the course of 
 the program), they just don't work the same as C or Fortran variables. In 
 fact, they work exactly the same as Javascript or Ruby variables.

Thank you!

+11

I get tired of the “Python doesn’t have variables” line.

What makes Python 
variables/bindings/references/aliases/namedvalues/slots/bucketsofstuff 
surprising to new arrivals from other language kingdoms, is that accessing is 
pragmatically implicit (walks the scope tree for you) and assignment may 
require explicitness. IOW, for some “variables”, you have to do something 
explicit to make the variable you want to refer to, vary. Some might say there 
is a lack of symmetry. Pros and cons.

Personally, I don’t care. It’s one of those lessons you just learn as you go.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: The sum of numbers in a line from a file

2014-02-20 Thread Travis Griggs

On Feb 20, 2014, at 8:54 AM, Dave Angel da...@davea.name wrote:

 kxjakkk kjaku...@gmail.com Wrote in message:
 Let's say I have a sample file like this:
 
 Name1   2 34 5  6 78
 
 name1099-66-7871   A-FY10067815998
 name2999-88-7766   A-FN99   100969190
 name3000-00-0110AUD5100281976
 name4398-72-P/FY7684496978
 name5909-37-3689A-FY97941006179
 
 For name1, I want to add together columns 4, 5, 6, and get an average from 
 that, then do the same for the last two columns. I want to do this for every 
 name. 
 
 All I've got is
 sum([int(s.strip()) for s in open('file').readlines()])
 
 
 Don'ttrytodoitallinoneline.thatwayyouactuallymighthaveaplacetoinse
 rtsomeextralogic.
 
Yes.

Clearly

the

preferred

way

to

do

it

is

with

lots

of

lines

with

room

for

expandability.

Sorry Dave, couldn’t resist. Clearly a balance between extremes is desirable.

(Mark, I intentionally put the blank lines in this time grin)

Travis Griggs
“Every institution tends to perish by an excess of its own basic principle.” — 
Lord Acton




-- 
https://mail.python.org/mailman/listinfo/python-list


Re: PyWart: More surpises via implict conversion to boolean (and other steaming piles!)

2014-02-11 Thread Travis Griggs

On Feb 10, 2014, at 10:30 PM, Steven D'Aprano st...@pearwood.info wrote:

 
1. Parenthesis should not be required for parameter- less functions.
 
 Of course they should. Firstly, parameter-less functions are a code-
 smell, and ought to be discouraged. Secondly, even if you have a good 
 reason for using one -- for example, random.random -- then the difference 
 between referring to the object and calling the object should be clear.

Interesting. Can you clarify or provide some links to the parameter-less 
functions are a code-smell” bit?

I agree with your points about consistency. I disagree with the original poster 
that niladic functions should have a different syntax than the others. I 
empathize with him, I’ve made the same mistake before (being an ardent 
Smalltalker in the past, it’s an easy habit to have bite you). But the 
consistency is more important. And in python, things “happen” when parentheses 
appear. I just accept that.

OTOH, I’m not sure I’ve heard the parameters-less functions are a code one? Is 
it just loose functions that you’re referring to? As opposed to methods (which 
are just bound functions)? I could maybe accept that. But methods with fewer 
arguments, and even none, are a desirable thing. There are code smells that are 
the opposite in fact, methods with long parameter lists are generally seen as 
code smell (“passing a paragraph”).

Anyway, I’d love to understand better what you see as the code smell and why.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: PyWart: More surpises via implict conversion to boolean (and other steaming piles!)

2014-02-11 Thread Travis Griggs

On Feb 11, 2014, at 7:52 AM, Chris Angelico ros...@gmail.com wrote:

 On Wed, Feb 12, 2014 at 2:36 AM, Travis Griggs travisgri...@gmail.com wrote:
 OTOH, I’m not sure I’ve heard the parameters-less functions are a code one? 
 Is it just loose functions that you’re referring to? As opposed to methods 
 (which are just bound functions)? I could maybe accept that. But methods 
 with fewer arguments, and even none, are a desirable thing. There are code 
 smells that are the opposite in fact, methods with long parameter lists are 
 generally seen as code smell (“passing a paragraph”).
 
 
 'self' is, imo, a parameter. When you call a parameter-less method on
 an object, it's usually an imperative with a direct object (or
 sometimes a subject):
 
 some_file.close() # Close some_file
 some_list.shuffle() # Shuffle some_list
 some_file.readline() # Some_file, read in a line
 
 There are times when, for convenience, the object is implicit.
 
 print(some text, file=some_file) # Print that text
 print(file=some_file) # Print a blank line
 print(some text) # Print that text to sys.stdout
 print() # Print a blank line to sys.stdout
 
 So in that situation, the no-args call does make sense. Of course,
 this is a call to a function that does take args, but it's accepting
 all the defaults and providing no additional content. It's quite
 different to actually define a function that mandates exactly zero
 arguments, and isn't making use of some form of implicit state (eg a
 closure, or maybe a module-level function that manipulates
 module-level state - random.random() would be an example of the
 latter). Syntactically, Python can't tell the difference between
 print() and foo() where foo can never take args.

So at this point, what I’m reading is that actually making a “no arg function” 
is difficult, if we widen the semantics. The “arguments” of a function may be 
bound to its implicit self parameter, or tied to module state.

 
 I'd say that a function taking no args is code smell, unless it's
 obviously taking its state from somewhere else (callbacks, for
 instance - maybe you pass a bound method, or maybe a closure, but in
 either case it has implicit state that's not described by function
 args); but _calling_ with no args isn't as smelly. It's certainly less
 common than using args, but there are plenty of times when a type is
 called without args, for instance[1].

Which leaves me wondering, how would I get my code to smell this way then? What 
IS an example of a no arg function that doesn’t have an implicit object, that 
smells? It seems I can  escape the smell clause, as long as I find some data 
that I reason is attached to my function.

This all aside, I don’t think these are what the OP had in mind. A code 
inspection algorithm is not going to be able to discern when an explicitly 
parameterless function has implicit parameters. It’s just going to see 
something like

print vs print()

or 

aPoint.transpose vs aPoint.transpose()

 
-- 
https://mail.python.org/mailman/listinfo/python-list


Metaprogramming question

2014-02-11 Thread Travis Griggs
The discussion about niladic functions, made me want to follow a segue and do 
some reflection/introspective programming in Python. I’ve not done a lot of 
that yet, and it seemed like an educational (well, at least entertaining) goose 
chase.

If I run the following code:

import datetime
datetime.datetime.now(13, 42)

I will get an error (expected). The error I will get is:

Traceback (most recent call last):
  File stdin, line 1, in module
TypeError: now() takes at most 1 argument (2 given)

So, at some point, there’s some metadata in the system attached to the builtin 
datetime.datetime.now method, that indicates 1 argument, tops.

So here’s my basic question. Is there anyway to programatically query that 
information in python code?

inspect.signature(datetime.datetime.now)

just gives a ValueError. inspect must only be good for the python code that I 
write, in python. Is there another way to dig out what the interpreter knows 
there?
-- 
https://mail.python.org/mailman/listinfo/python-list


Fun with function argument counts

2014-02-11 Thread Travis Griggs
After the recent discussion about the classic error:

if self.isFooBar:
  return 42

Among many thing, the OPs contention was that the ability to have this kind of 
error was a Bad Thing (tm). Which led to me asking about code smells and 
parameterless functions/methods.

So I got curious. Semantics of implicit objects aside, how often is it possible 
to write code like that. In short, how frequent are methods/functions that have 
zero explicit args (not implicit, because while fun, that’s not how we code 
them). It was a fun experiment, I’ve been doing python for a little over a year 
now, and I thought it would be enjoyable/educational to do a bit of 
metaprogramming. First the results though.

Below is a histogram of function argument count:

argCount x occurrences (% of total)
-1 x 10426 ( 3.2%) # these are where I stuffed all of the routines I couldn’t 
extract the argspecs for
 0 x 160763 (48.7%)
 1 x 109028 (33.0%)
 2 x 40473 (12.3%)
 3 x  7059 ( 2.1%)
 4 x  2383 ( 0.7%)
 5 x   141 ( 0.0%)
 6 x46 ( 0.0%)
 7 x12 ( 0.0%)
10 x 1 ( 0.0%)
16 x 1 ( 0.0%)
19 x 2 ( 0.0%)

Nearly half of the functions/methods I scanned were zero args (48.7). Which was 
more than I expected. I haven’t dug enough to see if there’s a flock of 
canaries in there or not. The code to produce that table is here: 
https://gist.github.com/anonymous/8947229. Yes, it’s hacky. Wasn’t trying to 
win any style/idiom awards with this one.

To get this table, I used PyPy 3-2.1 beta for OSX. I basically attempted to 
parse all of the modules found in it’s lib-python directory. A subset of the 
modules wouldn’t load, I’m not sure whether to write that off as the 
work-in-progress nature of pypy or what. And I black listed some of them (such 
as idlelib.idle, ctypes.test.*, etc). But from the counts, I was able to get a 
pretty large corpus of them.

I learned a number of fun things as part of the exercise:

1) I did not want to try load all modules at once into my environment. I 
suspect that would create problems. Using os.fork() to isolate the 
load/analysis of each module was a handy way to deal with that. The trick of 
using if pid: branch to split of the flow of execution was cool. Maybe it’s the 
wrong tool for the job and I missed an obvious one, but I thought it was kinda 
clever.

2) Using cpython, a lot of the core library can’t be reflected on. I tried to 
use the inspect module, and found that things like 
inspect.getmembers(datetime.datetime, inspect.ismethod) resulted in a big 
surprise. Especially if you leave off the predicate, and see that there are a 
lot of things in there that claim they ARE methods). I finally stumbled into 
inspect.isroutine, but found that most of the results couldn’t be reified using 
inspect.signature anyway. The “it’s all python, all the way down, well mostly” 
ideology of pypy ensured that a higher percentage opt the base libraries could 
be analyzed.

3) It’s easy to take 3.3.x for granted. I found right away that signature was 
introduced in 3.3, so I had to use inspect.getfullargspec() instead.

4) optional arguments were an interesting dillema. I chose to reduce the 
argument count of a signature by the number of default arguments. Since they 
are essentially optional. So the stats there have a bias to the “minimal” call 
signature.

5) my method of scanning loadable modules is probably very naive/brute 
force/stupid. I would love it if there was a better way to do that.

6) Who writes a function with 19 mandatory arguments anyway  
subprocess._execute_child() and distutils.cygwincompiler._execute_child()

7) I’m not entirely sure, given #6, that I’m not seeing inherited methods for 
all classes, so getting an overinflated count from them. Can anyone answer that?
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python 3.x adoption

2014-01-21 Thread Travis Griggs
Looks like the 2/3 topic has lain fallow for a couple of days, gotta keep it 
burning…

I’m  a relatively recent python convert, but been coding and talking to others 
about coding for many moons on this big blue orb. I think the industrial side 
of this debate has been talked up quite a bit. We have tools, we have the wall 
of shame/superpowers for libraries and projects.

I think the desires of the core of people moving python forward are pretty 
clear to those of us that plug in. Move to 3. Period. We can debate, hate it, 
go on all day, but they’ve been pretty steady.

I’ve had a bunch of interns around me lately though, wanting to get into 
python, and this is where I find the momentum really breaks down. If newcomers 
go to take an online course in python, they might try MIT’s Open Courseware 
(who doesn’t want to learn from the illustrious MIT after all?). They’ll be 
taught Python 2, not 3. Or they might try Code Academy. Again, they’ll be 
taught 2, not 3. If the newbie googles “python reference”… top link will be 
python 2.

So in my mind, the wall of superpowers/shame is no longer well aligned with 
where the real battlefront of adoption is at. The legacy of the internet caches 
and education sites are. Personally, I have no idea why an education site would 
favor a version that sooner or later they’re going to have to try and explain 
how super() works.

The other area, I think, that puts a dent in perceived adoption is in alternate 
interpreters. Back in the day, everyone was making some branch of python (e.g. 
IronPython, Jython, Cython, PyPy, Stackless, etc). All of them did python 2. 
Very few are doing python 3. Some have been abandoned (as is the nature of 
research endeavors like these were), but there doesn’t seem to be the broad 
swath of people still building alternate python expressions, especially in 
python 3. Being a fan of JIT, I have big hopes for PyPy, I can’t figure out why 
they aren’t pitching their “cutting edge” interpreter, for the “cutting edge” 
version of python. There should be a wall of superpowers/shame for interpreters.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: 'Straße' ('Strasse') and Python 2

2014-01-16 Thread Travis Griggs

On Jan 16, 2014, at 2:51 AM, Robin Becker ro...@reportlab.com wrote:

 I assure you that I fully understand my ignorance of ...

Robin, don’t take this personally, I totally got what you meant.

At the same time, I got a real chuckle out of this line. That beats “army 
intelligence” any day.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python 3.x adoption

2014-01-15 Thread Travis Griggs
Here we go again…

On Jan 14, 2014, at 11:33 AM, Staszek nore...@eisenbits.com wrote:

 Hi
 
 What's the problem with Python 3.x? It was first released in 2008, but
 web hosting companies still seem to offer Python 2.x rather.
 
 For example, Google App Engine only offers Python 2.7.
 
 What's wrong?...

Maybe what it means is that Python3 is just fine, but Google App Engine isn’t 
seeing a lot of development/improvement lately, that it’s just in maintenance 
mode. Imagine that, Google not finishing/maintaining something.

I wish amongst the periodic maelstroms of Python2 vs Python3 handwringing, 
people would look at the new project starts. When I work with someone’s old 
library that they’ve moved on from, I use python2 if I have to, but anytime I 
can, I use python3.

Personally, I wish they’d start python4, sure would take the heat out of the 3 
vs 2 debates. And maybe there’d be a program called twentyfour as a result.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: 'Straße' ('Strasse') and Python 2

2014-01-15 Thread Travis Griggs

On Jan 15, 2014, at 4:50 AM, Robin Becker ro...@reportlab.com wrote:

 On 15/01/2014 12:13, Ned Batchelder wrote:
 
 On my utf8 based system
 
 
 robin@everest ~:
 $ cat ooo.py
 if __name__=='__main__':
import sys
s='A̅B'
print('version_info=%s\nlen(%s)=%d' % (sys.version_info,s,len(s)))
 robin@everest ~:
 $ python ooo.py
 version_info=sys.version_info(major=3, minor=3, micro=3,
 releaselevel='final', serial=0)
 len(A̅B)=3
 robin@everest ~:
 $
 
 
 
 You are right that more than one codepoint makes up a grapheme, and that 
 you'll
 need code to deal with the correspondence between them. But let's not muddy
 these already confusing waters by referring to that mapping as an encoding.
 
 In Unicode terms, an encoding is a mapping between codepoints and bytes.  
 Python
 3's str is a sequence of codepoints.
 
 Semantics is everything. For me graphemes are the endpoint (or should be); to 
 get a proper rendering of a sequence of graphemes I can use either a sequence 
 of bytes or a sequence of codepoints. They are both encodings of the 
 graphemes; what unicode says is an encoding doesn't define what encodings are 
 ie mappings from some source alphabet to a target alphabet.

But you’re talking about two levels of encoding. One runs on top of the other. 
So insisting that you be able to call them all encodings, makes the term 
pointless, because now it’s ambiguous as to what you’re referring to. Are you 
referring to encoding in the sense of representing code points with bytes? Or 
are you referring to what the unicode guys call “forms”?

For example, the NFC form of ‘ñ’ is ’\u00F1’. ‘nThe NFD form represents the 
exact same grapheme, but is ‘\u006e\u0303’. You can call them encodings if you 
want, but I echo Ned’s sentiment that you keep that to yourself. 
Conventionally, they’re different forms, not different encodings. You can 
encode either form with an encoding, e.g.

'\u00F1'.encode('utf8’)
'\u00F1'.encode('utf16’)

'\u006e\u0303'.encode('utf8’)
'\u006e\u0303'.encode('utf16')

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: cascading python executions only if return code is 0

2013-12-26 Thread Travis Griggs

On Dec 22, 2013, at 10:37 AM, Frank Cui y...@outlook.com wrote:

 hey guys,
 
 I have a requirement where I need to sequentially execute a bunch of 
 executions, each execution has a return code. the followed executions should 
 only be executed if the return code is 0. is there a cleaner or more pythonic 
 way to do this other than the following ? 
 
 if a() == 0:
 if b() == 0:
 c()

I know I’m a little late to the game on this one. Good answers and interesting 
discussions (and sometimes not). In some situations, I might do something like 
the following. It depends on just how many functions your cascading, and how 
arbitrary or pluggable those are.

If your model is that you have a sort of todo list of functions to execute 
(more than 3 or so), you might want to separate the definition of that run list 
from the logic that executes them. Given something like:

def a():
  print(‘Aye’)
  return 0

def b():
  print(‘Bee’)
  return 0

def c():
  print(’See’)
  return 0

def d():
  print(‘Dee’)
  return 1

def e():
  print(‘Eee’)
  return 1

You do the nested if as you original proposed or the chained or as also 
proposed. Or you could put the commands in a list:

script = [
  a,
  b,
  c,
  d,
  e]

This gives you a nice succinct list of stuff that needs to be done, not to 
different if you’d just coded it with no or logic, e.g.

a
b
c
d
e

Refactoring/evolving them then feels the same.

To run the script we could do it the good ol’ C'ish way:

for step in script:
  if step() != 0:
break

But we have more functional style stuff via builtins which can capture that 
pattern:

ranToEnd = all(step() == 0 for step in script)

So IF you’re use case lends itself to separation of the “list of stuff to do” 
and the “logic to execute said list”, then… this approach might be appealing.

Travis Griggs


-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Newbie question. Are those different objects ?

2013-12-20 Thread Travis Griggs
On Dec 20, 2013, at 8:00 AM, Mark Lawrence breamore...@yahoo.co.uk wrote:

 A good point.  Shall I write a PEP asking for a language change which 
 requires that that stupid = sign is replaced by a keyword reading something 
 like thenameonthelefthandsideisassignedtheobjectontherighthandside ?

Or a symbol like :=. As a former Smalltalker, I still miss this as the 
assignment operator, and the “gets” verbiage that went along with it. One said:

x := 4

as in “x gets 4”

I always got a kick out of the following paragraph from 
http://james-iry.blogspot.com/2009/05/brief-incomplete-and-mostly-wrong.html.

1970 - Niklaus Wirth creates Pascal, a procedural language. Critics 
immediately denounce Pascal because it uses x := x + y syntax instead of the 
more familiar C-like x = x + y. This criticism happens in spite of the fact 
that C has not yet been invented.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: grab dict keys/values without iterating ?!

2013-12-11 Thread Travis Griggs

On Dec 11, 2013, at 5:31 AM, rusi rustompm...@gmail.com wrote:

 
 The classic data structure for this is the trie:
 General idea: http://en.wikipedia.org/wiki/Trie
 In python:
 http://stackoverflow.com/questions/11015320/how-to-create-a-trie-in-python/

My thoughts exactly!

If you wade through the comments there, someone has done a more-than-naive 
implementation here:

https://github.com/kmike/marisa-trie

The write up makes it look pretty favorable as well for performance (scroll 
2/3s down to the Benchmarks section).



-- 
https://mail.python.org/mailman/listinfo/python-list


Meta Fight About Posting (was: python programming help)

2013-12-09 Thread Travis Griggs

On Dec 9, 2013, at 1:34 AM, Mark Lawrence breamore...@yahoo.co.uk wrote:

 On 09/12/2013 05:07, ru...@yahoo.com wrote:
 On 12/08/2013 05:27 PM, Mark Lawrence wrote:
 On 09/12/2013 00:08, ru...@yahoo.com wrote:
 On 12/08/2013 12:17 PM, Chris Angelico wrote:
 On Mon, Dec 9, 2013 at 6:06 AM,  rafaella...@gmail.com wrote:[...]
 [...]
 To the OP, please ignore the above, it's sheer, unadulterated rubbish.
 Nobody has ever been bullied into doing anything.  People have however
 been asked repeatedly to either A) use the link referenced above to
 avoid sending double spaced crap here from the inferior google groups
 product or B) use an alternative technology that doesn't send double
 spaced crap.
 
 Mark, I appreciate your calm and reasonable requests for people
 to checkout the page you gave a link to, that's why I repeated
 your advice.  It is also why I responded to Chris and not to you.
 
 However it does not change the fact that people here have responded
 in rather extreme way to GG posts including calling GG users twits
 and claiming GG posts damage their eyesight, as well as repeatedly
 denying the obvious fact that GG is much easier to use for many than
 to subscribe to a usenet provider or to a mailing list.  One frequently
 sees words like crap, slimy, rubbish etc to describe GG posts
 which is pretty intimating to people who just want some help with a
 python question using a tool they already know how to use and have
 had no complaints about in other places.
 
 
 Well you can ask iMath, amongst others, not to send double spaced google 
 nonsense.  They've been asked repeatedly, politely, but apparently have no 
 consideration at all for people who have no interest in seeing this ill 
 formed dross spread throughout web land.

As long as we’re in full scale rant drift, I’d like to remind others of the 
time honored tradition of changing the post subject, when, er, uh, the subject 
changes. Because this obviously is not programming help anymore.

The python mailing list is the only one I know of that is cross posted between 
3 different technologies. Maybe it’s an outgrowth of the “multi paradigm” 
philosophy of python or something.

It would be an interesting experiment, to shut down the cross forum replication 
engines for a month. Personally, I think they should each thrive, or die, on 
their own. If there’s enough mass on the groups to answer the occasional one 
off question, it’ll go on, indifferent of the existence of the mailing list. 
Comp.lang.python can truly become a troll haven. :) And the mailing list can be 
for the more thorough threads, or something.

If you’re worried about “fragmentation”… these weekly rants seem to indicate 
it’s happened anyway, and the impedance mismatch between 
styles/technologies/formats is generating more heat from friction than it is 
contributing light to the cross-sharing. Besides, there’s nothing stopping 
periodic posts being sent to any of the sites saying “by the way, did you know 
there’s also a mailing list…”

The nice thing about doing it for a month (or so), is that it’s not a “huge 
disturbance in the force.”  If it stinks, you turn them back on in a month (or 
so).

tongue  in=“cheek”If you’re still not sold, and find yourself solidly in the 
“keep it all together” group, I propose, we embrace that idea, and set up a 
bi-directional engine between the IRC channel (which I’ve found very helpful 
often) and the mailing list. /
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Packaging a proprietary Python library for multiple OSs

2013-12-05 Thread Travis Griggs

On Dec 5, 2013, at 2:56 AM, rusi rustompm...@gmail.com wrote:

 3. https://groups.google.com/forum/#!forum/python-virtualenv may be a better 
 place to ask

Am I the only one that sees the irony in this suggestion? Given the long 
running tirades^H^H^H^H^H^H thread about “Managing Google Groups headaches”?

“Pleassse don’t use Google Groupesss. It’sss nasssty. It hurtssess our 
eyessse with itsss long lineieesss. Unless it ha a ssspecial 
ned. Then the groupssesss are OK, Ye?
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Managing Google Groups headaches

2013-12-04 Thread Travis Griggs

On Dec 4, 2013, at 6:52 AM, Rich Kulawiec r...@gsp.org wrote:

 Yes, I'm
 aware of web forums: I've used hundreds of them.  They suck.  They ALL
 suck, they just all suck differently.  I could spend the next several
 thousand lines explaining why, but instead I'll just abbreviate: they
 don't handle threading, they don't let me use my editor of choice,
 they don't let me build my own archive that I can search MY way including
 when I'm offline, they are brittle and highly vulnerable to abuse
 and security breaches, they encourage worst practices in writing
 style (including top-posting and full-quoting), they translate poorly
 to other formats, they are difficult to archive, they're even more
 difficult to migrate (whereas Unix mbox format files from 30 years ago
 are still perfectly usable today), they aren't standardized, they
 aren't easily scalable, they're overly complex, they don't support
 proper quoting, they don't support proper attribution, they can't
 be easily forwarded, they...oh, it just goes on.   My point being that
 there's a reason that the IETF and the W3C and NANOG and lots of other
 groups that could use anything they want use mailing lists: they work.

One of the best rants I’ve ever read. Full mental harmonic resonance while I 
read this. Hope you don’t mind, but I think I’ll be plagiarizing your comments 
in the future. Maybe I’ll post it on a couple of the web forums I currently 
have the luxury of regularly hating.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python for microcontrollers

2013-12-03 Thread Travis Griggs

On Dec 3, 2013, at 6:18 AM, Colin J. Williams c...@ncf.ca wrote:

 On 03/12/2013 7:58 AM, Mark Lawrence wrote:
 I thought this might be of interest
 Http://www.kickstarter.com/projects/214379695/micro-python-python-for-microcontrollers
 
 
 Is this intended to be better than the Raspberry PI?  RPi handles Python 2 or 
 3.
 
 How would it differ?

IMO, a whole different class of computer. From that page, the board they’re 
targeting “... clocked at 168MHz and has 1MiB flash and 192KiB RAM.” They’re 
running OS-less.

The Pi, on the other hand actually runs a full OS (Linux) and has specs like 
700 MHz, 512MB Ram, and an sd card for storage which means you’re going to have 
to work hard to find something as small as 2G, the sweet price point is going 
to actually give you 8G.

Whether or not you go for their board, they’re targeting a compute environment 
that is 5x-ish slower, has at least 2000x less storage space, and works with 
about a thousandth of the ram of a Pi.

Having forayed into the world of small small micro controllers myself this last 
year and a half, I’m kind of torn on whether this is a good idea or not. But I 
think it’s cool they’re trying. And I’d definitely try it to see how it worked 
out.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Managing Google Groups headaches

2013-11-28 Thread Travis Griggs


Sent from my iPhone

 On Nov 28, 2013, at 7:40, Michael Torrie torr...@gmail.com wrote:
 
 On 11/28/2013 08:08 AM, Chris Angelico wrote:
 Which is easier, fiddling around with your setup so you can post
 reasonably on Google Groups, or just getting a better client? With
 your setup, you have to drop out to another editor and press F9 for it
 to work. With pretty much any other newsreader on the planet, this
 works straight off, no setup necessary.
 
 I'm still going to advise people to stop using buggy rubbish.
 
 My opinion is that the Python list should dump the Usenet tie-in and
 just go straight e-mail.  Python is the only list I'm on that has a
 usenet gateway.
 
 I used to love usenet back in the day, but in the present internet
 climate makes it unworkable, though I concede that e-mail is reaching
 the end of its usefulness as well.
 
 I wouldn't oppose a dual e-mail list and web-based forum system,
 provided the forum system supported threaded conversations in a clean
 and useful way (maybe like google wave used to).
 -- 
 https://mail.python.org/mailman/listinfo/python-list

Here! Here! Well said and amen. My thoughts exactly.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: tkinter bug on mac maverick python 3.3.3

2013-11-27 Thread Travis Griggs

On Nov 27, 2013, at 3:32 AM, Dan Wissme wis...@hotmail.com wrote:

 Hi !
 Am I the only one to get a bug in GUIs using tkinter on my Mac under maverick 
 and Python 3.3.3 ?
 When will they get rid of Tcl/Tk which causes recurrent problems at almost 
 each new Python version !
 Please, for the rest of us...

I’m curious, if they get rid of Tcl/Tk as you wished, what do you propose 
replacing it with?

It’s not like there are other “light weight cross platform ui frameworks” that 
are obvious replacements. Most of the others are far heavier. And all have 
issues with their purported cross platformness.

Or are you proposing that Tcl/Tk be moved out of the python core distro, and 
instead delivered as a separate package? If *this* is your proposal, I 
wholeheartedly agree. Just the other day, I was working on putting python3 on a 
beaglebone black (similar to a raspberry pi). It built OK, but I had to ignore 
lots of warnings about Tcl/Tk not working, which of course was a “duh”.

I was surprised, that among some, there’s a sentiment that python core MUST 
include it. Which was interesting. One of the core principles of this language 
is all about modules and modularity. Why can’t the Tcl/Tk module be the same as 
numpy and scipy and many of the other widely 
installed-after-the-fact-as-appropriate packages?
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How to install pip for python3 on OS X?

2013-11-22 Thread Travis Griggs

On Nov 20, 2013, at 6:01 AM, Mark Lawrence breamore...@yahoo.co.uk wrote:

 On 20/11/2013 06:55, Travis Griggs wrote:
 OSX (Mavericks) has python2.7 stock installed. But I do all my own
 personal python stuff with 3.3. I just flushed my 3.3.2 install and
 installed the new 3.3.3. So I need to install pyserial again.
 
 Just idle curiosity but why do you have to do this?  On Windows I just whack 
 3.3.3 over the top of 3.3.2, job done.

I think in this case, it was a chance to clean house, and maybe up the “tools” 
game (e.g. use pip) instead of what I had been doing. So you’re correct. The 
flushing of 3.3.2 was more that I *wanted* to, instead of *needing* to.

(aside. I do not use GoogleGroups, but have been accused of somehow sending 
email that looks like I do. Does this email look like that?)
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How to install pip for python3 on OS X?

2013-11-22 Thread Travis Griggs

On Nov 19, 2013, at 11:27 PM, Ned Deily n...@acm.org wrote:

 In article 6856a21c-57e8-4cdd-a9e8-5dd738c36...@gmail.com,
 Travis Griggs travisgri...@gmail.com wrote:
 
 OSX (Mavericks) has python2.7 stock installed. But I do all my own personal 
 python stuff with 3.3. I just flushed my 3.3.2 install and installed the new 
 3.3.3. So I need to install pyserial again. I can do it the way I've done it 
 before, which is:
 
 Download pyserial from pypi
 untar pyserial.tgz
 cd pyserial
 python3 setup.py install
 But I'd like to do like the cool kids do, and just do something like pip3 
 install pyserial. But it's not clear how I get to that point. And just that 
 point. Not interested (unless I have to be) in virtualenv 
 yet.-
 
 http://www.pip-installer.org/en/latest/installing.html
 
 # download and install setuptools
 curl -O https://bitbucket.org/pypa/setuptools/raw/bootstrap/ez_setup.py
 python3 ez_setup.py
 # download and install pip
 curl -O https://raw.github.com/pypa/pip/master/contrib/get-pip.py
 python3 get-pip.py
 # use pip to install
 python3 -m pip install pyserial
 # Don't want it?
 python3 -m pip uninstall pyserial
 
 -- 
 Ned Deily,
 n...@acm.org

Ned,

Thank you! Belatedly. I’ve had some fires to put out at work. And have gotten 
back to this, and this is exactly what I was looking for. I added the 
additional step of:

cd /usr/local/bin
ln -s ../../../Library/Frameworks/Python.framework/Versions/3.3/bin/pip pip 

Works, like a charm.

(aside. I do not use GoogleGroups, but have been accused of somehow sending 
email that looks like I do. Does this email look like that?)

-- 
https://mail.python.org/mailman/listinfo/python-list


How to install pip for python3 on OS X?

2013-11-19 Thread Travis Griggs
OSX (Mavericks) has python2.7 stock installed. But I do all my own personal 
python stuff with 3.3. I just flushed my 3.3.2 install and installed the new 
3.3.3. So I need to install pyserial again. I can do it the way I've done it 
before, which is:

Download pyserial from pypi
untar pyserial.tgz
cd pyserial
python3 setup.py install
But I'd like to do like the cool kids do, and just do something like pip3 
install pyserial. But it's not clear how I get to that point. And just that 
point. Not interested (unless I have to be) in virtualenv yet.-- 
https://mail.python.org/mailman/listinfo/python-list


What to make of 'make test' for python3 install from source (beaglebone angstrom install).

2013-11-07 Thread Travis Griggs
After hints here and there from different channels, and a pretty good 
StackOverflow post on the subject, I've concluded that out of the box, the 
install from source utilities don't really provide many hooks for making a 
custom/minimal install. Best bet is basically to do the standard install, and 
then go trim off the fat that wasn't called for. If not that, you really have 
to take ownership of the whole build process (e.g. as Debian and others do). 
Thanks to Ned and others for helping along the way.

One part of the recommended install is to 'make test'. In a perfect world, I 
guess everything would pass. Since I'm running an embedded linux, on an arm 
processor, I kind of expect some issues. As the tests run, I see that there are 
indeed some errors here and there. But I don't see where they get summarized or 
anything. I guess I can try to capture the output and grep through it. I'm 
curious how people use the make install. Looking to bootstrap off of other's 
experience, if any has some willing to share.


asideI find this is a tricky topic to get help with. Most of the python 
mailing list and irc channel is really about _python_ questions. Not the meta 
aspect of building it. And the python-dev guys make it pretty clear (in a nice 
way) that python-dev is for developing the next version of python (3.4 at the 
moment). They're probably the ones that really know these answers more than the 
lay python developer though. It's too bad there's not a forum in between to 
share/ask for help with these kinds of things./aside


--Travis Griggs
I multiply all estimates by pi to account for running around in circles
-- 
https://mail.python.org/mailman/listinfo/python-list


Compiling Python3 for BeagleBone Black (Angstrom distro)

2013-11-04 Thread Travis Griggs
I'm playing with a BeagleBone Black running the angstrom distro. Of course, 
stock python is 2.7, I'd rather use python3. There isn't a python3 package 
available for angstrom. So I downloaded the source and compiled. It seemed to 
work pretty well. I used the basic approach outlined in the REAMDE:

./configure
make
make test
make install

Now, I want to repeat the process, but be a little more judicious about what 
all is compiled. For example, I don't really need tk stuff (in fact, it just 
kept telling me it wasn't there). And there's probably a number of other 
modules/libraries in the kitchen sink known as the stock install, that I could 
forgo on a tiny little computer like this.

I see, looking at ./configure --help | less, that I could provide 
--disable-FEATURE and --without-PACKAGE directives to my ./configure 
invocation. But what I don't see is how to generate a list of what 
FEATURES/PACKAGES I could put there for consideration of omission. Is there 
some magic juju that generates that?

Travis Griggs
--I multiply all estimates by tau to account for running around in circles
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Compiling Python3 for BeagleBone Black (Angstrom distro)

2013-11-04 Thread Travis Griggs

On Nov 4, 2013, at 9:22 AM, Travis Griggs travisgri...@gmail.com wrote:

 I'm playing with a BeagleBone Black running the angstrom distro. Of course, 
 stock python is 2.7, I'd rather use python3. There isn't a python3 package 
 available for angstrom. So I downloaded the source and compiled. It seemed to 
 work pretty well. I used the basic approach outlined in the REAMDE:
 
 ./configure
 make
 make test
 make install
 
 Now, I want to repeat the process, but be a little more judicious about what 
 all is compiled. For example, I don't really need tk stuff (in fact, it just 
 kept telling me it wasn't there). And there's probably a number of other 
 modules/libraries in the kitchen sink known as the stock install, that I 
 could forgo on a tiny little computer like this.
 
 I see, looking at ./configure --help | less, that I could provide 
 --disable-FEATURE and --without-PACKAGE directives to my ./configure 
 invocation. But what I don't see is how to generate a list of what 
 FEATURES/PACKAGES I could put there for consideration of omission. Is there 
 some magic juju that generates that?
 

Should I have asked this question on python-dev instead? Not currently 
subscribed there… but would if that would generate more informed responses.

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: python IDE and function definition

2013-09-24 Thread Travis Griggs

On Sep 23, 2013, at 8:06 AM, Chris Friesen cbf...@mail.usask.ca wrote:

 
 Hi all,
 
 I'm looking for a python IDE (for Linux) that can look at code like this:
 
 class ConductorManager(manager.Manager):
def compute_recover(self, context, instance):
self.compute_api.stop(context, instance, do_cast=False)
 
 where I could highlight the stop and ask it to go to the definition. (Where 
 the definition is in a different file.)
 
 I'm running into issues where my current IDE (I'm playing with Komodo) can't 
 seem to locate the definition, I suspect because it's too ambiguous.
 
 The fact that python is dynamically typed seems to mean that there could 
 potentially be multiple answers, any class with a stop() method with the 
 right signature could presumably be plausible, right?  So rather than give 
 up, I'd like to have my IDE suggest all possible answers.

Hi Chris,

Not sure if this reproduces what you want or not. I use PyCharm (free for free 
stuff, and very affordable/worthwhile otherwise) on Linux (as well as 
OSX/Windows). I made a new project, added two files:

provider.py:

class Provider(object):
def stop(self):
pass

usage.py:

class Conglomerate(object):
def doSomething(self):
self.provision.stop()

I then highlight 'stop', hit Ctrl-B (menu option go todeclarations) and it 
brings up all the stop() definitions it could find, the Provider one on the 
top, click it and I jump there. Ctrl-Alt-B (menu option for 
gotoimplementation(s)) does nothing… UNLESS… I add this method to 
Conglomerate:

def __init__(self):
super.__init__()
self.provision = Provider()

Then go to implementations takes me right there to the other file.

HTH
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: iterating over a file with two pointers

2013-09-18 Thread Travis Griggs

On Sep 18, 2013, at 5:07 AM, nikhil Pandey nikhilpande...@gmail.com wrote:

 On Wednesday, September 18, 2013 4:51:51 PM UTC+5:30, Chris Angelico wrote:
 On Wed, Sep 18, 2013 at 9:12 PM, nikhil Pandey nikhilpande...@gmail.com 
 wrote:
 
 hi,
 
 I want to iterate over the lines of a file and when i find certain lines, i 
 need another loop starting from the next of that CERTAIN line till a few 
 (say 20) lines later.
 
 so, basically i need two pointers to lines (one for outer loop(for each 
 line in file)) and one for inner loop. How can i do that in python?
 
 please help. I am stuck up on this.
 
 
 
 After the inner loop finishes, do you want to go back to where the
 
 outer loop left off, or should the outer loop continue from the point
 
 where the inner loop stopped? In other words, do you want to locate
 
 overlapping sections, or not? Both are possible, but the solutions
 
 will look somewhat different.
 
 
 
 ChrisA
 
 Hi Chris,
 After the inner loop finishes, I want to go back to the next line from where 
 the outer loop was left i.e the lines of the inner loop will be traversed 
 again in the outer loop.
 1I iterate over lines of the file
 2 when i find a match in a certain line, i start another loop till some 
 condition is met in the subsequent lines
 3 then i come back to where i left and repeat 1(ideally i want to delete 
 that line in inner loop where that condition is met, but even if it is not 
 deleted, its OK)


Just curious, do you really need two loops and file handles? Without better 
details about what you're really doing, but as you've provided more detail, it 
seems to me that just iterating the lines of the file, and using a latch 
boolean to indicate when you should do additional processing on lines might be 
easier. I modified Chris's example input to look like:

alpha
*beta
gamma+
delta
epsilon
zeta
*eta
kappa
tau
pi+
omicron

And then shot it with the following:

#!/usr/bin/env python3
with open(samplein.txt) as file:
reversing = False
for line in (raw.strip() for raw in file):
if reversing:
print('', line[::-1], '')
reversing = not line.endswith('+')
else:
print(line)
reversing = line.startswith('*')

Which begins reversing lines as its working through them, until a different 
condition is met.

Travis Griggs


-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How do I calculate a mean with python?

2013-09-17 Thread Travis Griggs

On Sep 16, 2013, at 4:33 PM, William Bryant gogobe...@gmail.com wrote:

 Hey I am new to python so go easy, but I wanted to know how to make a program 
 that calculates the maen.
 
 List = [15, 6, 6, 7, 8, 9, 40]
 def mean():
global themean, thesum
for i in List:
thecount = List.count(i)
thesum = sum(List)
themean = thesum / thecount
 
 Why doesn't this work?
 -- 
 https://mail.python.org/mailman/listinfo/python-list

You've had a number of interesting and good responses, some holding your hand 
quite a bit, and others differently.

I think there's a different way to learn what's going wrong, that ISN'T 
mentioned here, and for some people it's a quite effective method of learning. 
I'm a relatively recent import from the Smalltalk community, where this 
approach is more prevalent, I wish it were more so in the Python community.

The way I suggest is to use a debugger. The nice thing about a debugger, is 
that you add a call to mean() at the end, put a breakpoint right there, run, 
and then you can visually walk through what it's doing. This can help find your 
bug, but probably also clarify how Python works in the first place. I use 
pycharm (anyone can use it for free). And there are probably others for free as 
well. 

-- 
https://mail.python.org/mailman/listinfo/python-list


Simple security between prototype iPhone app and SimpleHTTPServer REST service?

2013-09-17 Thread Travis Griggs
I'm prototyping a simple data collection service. I've implemented a simple 
REST API implemented with python 3x stock HTTPServer. And a simple iPhone app 
that submits data via a json/POST. And it all works just great when my iPhone 
is on the same network as the server.

But now I want to go the next step. I don't need to move beyond prototype/PoC 
yet, I just want to be able to do it outside of our internal network. Issues 
aside of getting access, name resolution, a port and that kind of stuff... what 
kind of security should I add to it? I might as well be a complete neophyte in 
this area. I've read a number of posts and such, and I get some of the pieces, 
at some level, but any confidence how to put that part of a web stack together 
elude me.

I found a example of how to add SSL to my python service 
(https://gist.github.com/ubershmekel/6194556). If I can figure out how to get 
the right keys embedded into my iPhone app (it's just on my phone, not anyone 
else's), is that enough? Or should I include some sort of auth? If so, what 
kind? And any pointers to how to start that would be much appreciated.

Some have blithely replied that I should be using Flask or Tornado. I get that 
I'm going to hit a wall with HTTPServer and that it's more of a toy 
implementation. But I don't want to get buried in learning a big framework 
either. If it was relatively easy to convert my simple REST service to one 
running on Tornado or Flask, without loading a bunch of other frameworks, and I 
got easy access to security services and good examples how to do them, that'd 
be fine with me. So far, my searches haven't turned up the simple recipe of 
so, you've made a simple REST API with HttpServer, here's how to take it to 
the semi secure public level using a real web framework.

Travis Griggs
-- I multiple all estimates by pi to account from running around in circles.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Style help for a Smalltalk-hack

2012-10-23 Thread Travis Griggs

On Oct 22, 2012, at 6:33 PM, MRAB pyt...@mrabarnett.plus.com wrote:

 Another way you could do it is:
 
 while True:
chunk = byteStream.read(4)
if not chunk:
break
...
 
 And you could fetch multiple signatures in one read:
 
 signatures = list(struct.unpack('{}I'.format(valveCount), byteStream.read(4 
 * valueCount)))

Thanks, both great ideas. Still does the read/decode slightly different between 
the different sites, but at least it's localized better. Much appreciated.

--
Travis Griggs
History has a habit of changing the people who think they are changing it. 
-Terry Pratchett

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Style help for a Smalltalk-hack

2012-10-23 Thread Travis Griggs

On Oct 22, 2012, at 6:33 PM, MRAB pyt...@mrabarnett.plus.com wrote:

 By the way, in Python the recommended style for variable names (well,
 what you'd call a 'variable' in other languages :-)) is lowercase with
 underscores, e.g. byte_stream.

We went with the 

...mixedCase is allowed only in contexts where that's already the prevailing 
style (e.g. threading.py), to retain backwards compatibility…

escape clause. :)

The group of us here are working in multiple languages, and all use it 
(mixedCase) across all of them. Because PEP 8 makes it clear up front that 
internal consistency is preferred,  we felt justified in marching on.

--
Travis Griggs
A vital ingredient of success is not knowing that what you're attempting can't 
be done. -Terry Pratchett

-- 
http://mail.python.org/mailman/listinfo/python-list


Style help for a Smalltalk-hack

2012-10-22 Thread Travis Griggs
I'm writing some code that does a structured read from formatted binary file. 
The code I came up with looks like:

# get the first four bytes, the first gap field
chunk = byteStream.read(4)
while chunk:
# interpret the gap bytes
gap, = struct.unpack('I', chunk)
# suck off the valveCount
valveCount, = struct.unpack('I', byteStream.read(4))
# collect the next valveCount signatures
signatures = [struct.unpack('I', byteStream.read(4))[0] for _ in 
range(valveCount)]
self.script.append(ScriptSpan(gap=gap, valveSet=signatures))
# now get the next 4 bytes for the gap of the next iteration, it'll be 
empty if we're at end
chunk = byteStream.read(4)

I can't help but thinking that there's some better way (i.e. more pythonic) to 
do this that doesn't involve having to use another module (Construct) or 
exploring generators or something like that. What bugs me about it is that 
there is two different styles for reading/decoding values from the byte stream. 
valveCount and signatures are both paired invocations of unpack() and read(). 
But to detect the end of the stream (file), I have to split the read() and 
unpack() of the gap value across 3 different lines of the code, and they don't 
even sit adjacent to each other.

I'm wandering up the Python curve with a passel of Smalltalk experience under 
my belt, so I expect I'm struggling with trying to map something like this 
across to python

[byteStream atEnd] whileFalse: [
 gap := (byteStream next: 4) asInteger.
 valveCount := (byteStream next: 4) asInteger.
 signatures := (1 to: valveCount) collect: [:_ | (byteStream next: 4) 
asInteger].
 self script add: (ScriptSpan gap: gap valveSet: signatures).
]

The part that doesn't seem to be there in the standard python library is the 
idea of an atEnd message for streams, it's inferred as a byproduct of a read().

Please be gentle/kind. I'm still learning. :) TIA

--
Travis Griggs
A vital ingredient of success is not knowing that what you're attempting can't 
be done. -Terry Pratchett

-- 
http://mail.python.org/mailman/listinfo/python-list


Reusable (local) Modules

2012-09-07 Thread Travis Griggs
I'm relatively new to Python (coming from strong C and Smalltalk backgrounds). 
I've written a couple of relatively small apps (one or two .py files). I'm 
using PyCharm (I love it).

I'm curious what the pythonic approach is to creating your own reusable 
modules. Any tutorials or high level explanations, or detailed, much 
appreciated. 

For example, I have a small module called valvenumbers.py. It's a family of 
functions that we use to do a variety of things with the serial numbers we 
attach to some of our products. Now I'm making a little desktop app using 
wxpython, and I want to use (import) that module. Using PyCharm, I have two 
separate projects in sibling directories. And there's another separate command 
line tool that wants to do the same. Currently, I just place a symlink to the 
valvenumbers.py, local to the directory of these apps. This seems like the 
quickest thing that could possibly work, but I'm assuming there's a more 
pythonic way to approach this general problem.

TIA!

Travis Griggs
Simplicity is the ultimate sophistication. -- Leonardo Da Vinci

-- 
http://mail.python.org/mailman/listinfo/python-list


Looking for some PyPI query help

2011-02-22 Thread Travis Griggs
Howdy Python brethren. I'm a Smalltalker, doing a bit of research on packaging 
ecospaces, in other languages and environments (I just finished examining 
Debian for example). I found what seems to be the big repository at PyPI. What 
would be enough for me, is to enumerate all of the packages there, and 
associate it with the number of prerequisite/dependent/imports it specifies. I 
don't need it to recurse thru dependents, just the immediate count.

My goal is to be able to histogram the data, and be able to answer questions 
along the following lines:
1) What's the average/median dependent count in the Python ecospace.
2) For a given threshold (say 90%) when sorted by count, what's the count (e.g. 
90% of Python packages depend directly on 5 or less other packages).
3) What's the most number of dependents any package has ever specified?

Thanks for any help or pointers or hints or data you can give me.

(I apologize if this is overtly naive).

--
Travis Griggs
Objologist
I did not have time to write you a short program, so I wrote you a long one 
instead.

-- 
http://mail.python.org/mailman/listinfo/python-list