Re: Array of Functions
I second the call for a more concrete implementation, but if you want the results of the functions in c3 to be responsive to the values of c1 and c2 (i.e., if you change r1c1, r1c3 returns a different value), it might be worth encapsulating the whole thing in an object and making the c3 functions properties, which is Python for 'preprocessed attributes.' On Friday, November 14, 2014 5:17:38 PM UTC-5, Richard Riehle wrote: > In C, C++, Ada, and functional languages, I can create an array of functions, > albeit with the nastiness of pointers in the C family. For example, an > array of functions where each function is an active button, or an array of > functions that behave like formulae in a spreadsheet. I am finding this a > bit challenging in Python. > > Example: > > r1c1 r1c2 r1c3 > r2c1 r2c2 r2c3 > r3c1 r3c2 r3c3 > > where r1 is row 1 and c1 is column 1. Suppose I want an array where the > colum three is a set of functions that operates on the other two columns, > depending on the values I set for those rows and columns?As noted, I can > do this pretty easily in most languages (well, except for Java which does not > support any kind of functional programming capability), even if I have to use > pointers. > > I think my difficulty is related to the REPL nature of Python. However, I am > sure some clever Pythonista has found a way to do this. > > Thanks in advance for any suggestions, > > Richard Riehle, PhD, International Technological University, San Jose, CA -- https://mail.python.org/mailman/listinfo/python-list
Re: Newbie question about text encoding
I'm 100% in favor of expanding Unicode until the sun goes dark. Doing so helps solve the problems affecting speakers of "underserved" languages--access and language preservation. Speakers of Mongolian, Cherokee, Georgian, etc. all deserve to be able to interact with technology in their native languages as much as we speakers of ASCII-friendly languages do. Unicode support also makes writing papers on, dictionaries of, and new texts in such languages much easier, which helps the fight against language extinction, which is a sadly pressing issue. Also, like, computers are big. Get an external drive for your high-resolution PDF collection of Medieval manuscripts if you feel like you're running out of space. A few extra codepoints aren't going to be the straw that breaks the camel's back. On Thursday, February 26, 2015 at 8:24:34 AM UTC-5, Chris Angelico wrote: > On Thu, Feb 26, 2015 at 11:40 PM, Rustom Mody wrote: > > Wrote something up on why we should stop using ASCII: > > http://blog.languager.org/2015/02/universal-unicode.html > > >From that post: > > """ > 5.1 Gibberish > > When going from the original 2-byte unicode (around version 3?) to the > one having supplemental planes, the unicode consortium added blocks > such as > > * Egyptian hieroglyphs > * Cuneiform > * Shavian > * Deseret > * Mahjong > * Klingon > > To me (a layman) it looks unprofessional - as though they are playing > games - that billions of computing devices, each having billions of > storage words should have their storage wasted on blocks such as > these. > """ > > The shift from Unicode as a 16-bit code to having multiple planes came > in with Unicode 2.0, but the various blocks were assigned separately: > * Egyptian hieroglyphs: Unicode 5.2 > * Cuneiform: Unicode 5.0 > * Shavian: Unicode 4.0 > * Deseret: Unicode 3.1 > * Mahjong Tiles: Unicode 5.1 > * Klingon: Not part of any current standard > > However, I don't think historians will appreciate you calling all of > these "gibberish". To adequately describe and discuss old texts > without these Unicode blocks, we'd have to either do everything with > images, or craft some kind of reversible transliteration system and > have dedicated software to render the texts on screen. Instead, what > we have is a well-known and standardized system for transliterating > all of these into numbers (code points), and rendering them becomes a > simple matter of installing an appropriate font. > > Also, how does assigning meanings to codepoints "waste storage"? As > soon as Unicode 2.0 hit and 16-bit code units stopped being > sufficient, everyone needed to allocate storage - either 32 bits per > character, or some other system - and the fact that some codepoints > were unassigned had absolutely no impact on that. This is decidedly > NOT unprofessional, and it's not wasteful either. > > ChrisA -- https://mail.python.org/mailman/listinfo/python-list
Online offline Python apps
Have you tried a conditional/try-catch block in your __init__? Something like class MyDBConn(object): def __init__(self, **db_kwargs): try: db = some_db.connect(**db_kwargs) except some_db.ConnectionError: db = my_fake_db() finally: self.db = db You might have to write an adapter to make sure you can treat the fake db and real db the same way, but that shouldn't be too hard. -- https://mail.python.org/mailman/listinfo/python-list
Multiple thread program problem
proc(f) isn't a callable, it's whatever it returns. IIRC, you need to do something like 'start_new_thread(proc, (f,))' -- https://mail.python.org/mailman/listinfo/python-list
Re: Storing instances using jsonpickle
1) There are, if you want to mess around with them, ways to make pickle
"smarter" about class stuff:
https://docs.python.org/2/library/pickle.html#pickling-and-unpickling-normal-class-instances
. I've never worked with any of this stuff (and people don't seem to like
pickle all that much), and I honestly think it might just be easier to
serialize class _data_ and then either create a factory that reads in e.g. a
json file and outputs class instances, or tweak __init__/__new__ to take the
data as an input.
2) re: "pyson," I'm pretty sure there are serialization formats that let you do
this kind of thing. I feel like I was _just_ reading about one somewhere, but
scrolling back through my browser history for the last 10 days or so turns up
nothing (it definitely included some kind of extension functionality,
though...). You could possibly approximate something like that with e.g. JSON
and some crafty en-/decoding, maybe like '"mySet: {"set": [0,1,2]}, "myTuple":
{"tuple": [0,1,2]}, "myObj": {"ClassName": {"foo": "bar", "baz": "quux"}}" + a
parser?
On Wednesday, September 3, 2014 10:19:07 PM UTC-4, Ned Batchelder wrote:
> On 9/3/14 6:30 PM, Josh English wrote:
>
> > On Wednesday, September 3, 2014 1:53:23 PM UTC-7, Ned Batchelder wrote:
>
> >
>
> >> Pickle (and it looks like jsonpickle) does not invoke the class'
>
> >> __init__ method when it reconstitutes objects. Your new __init__ is not
>
> >> being run, so new attributes it defines are not being created.
>
> >>
>
> >> This is one of the reasons that people avoid pickle: being completely
>
> >> implicit is very handy, but also fragile.
>
> >>
>
> >
>
> > I seem to remember having this exact same frustration when I used pickle
> > and shelve 15 years ago. I had hoped to have another way around this. I
> > spent over a decade trying to make an XML-based database work, in part
> > because of this limitation.
>
> >
>
> > Some days I get so frustrated I think the only data structure I should ever
> > use is a dictionary.
>
> >
>
> > I suppose to make this sort of thing work, I should look at creating custom
> > json encoders and decoders.
>
> >
>
>
>
> Typically, you need to decide explicitly on a serialized representation
>
> for your data. Even if it's JSON, you need to decide what that JSON
>
> looks like. Then you need to write code that converts the JSON-able
>
> data structure (dict of lists, whatever) into your object. Often a
>
> version number is a good idea so that you have some chance of using old
>
> data as your code changes.
>
>
>
> --
>
> Ned Batchelder, http://nedbatchelder.com
--
https://mail.python.org/mailman/listinfo/python-list
Pex import problems
Hi all, I'm trying to use Pex (http://pex.readthedocs.org/en/latest/index.html) to include requests in a little script to ping a server from a machine that doesn't come with pip (or much of anything, really) installed. I'm running into problems outputting a pex file that depends on a local script. I've got a command-line file, `client.py`, that can be called with a few command-line options. I can run `pex -r requests -o client.pex -- client.py`, but when I try `./client.pex -h` I get an error about "no such file or directory: '-h'". Ok, next attempt: `pex -r requests -o client.pex -e client` --> "ImportError: No module named client". I dug around in the code a bit, and from what I can tell, `-e FOO` boils down to `__import__(FOO)`, which I can do, both from the interpreter and from a test script. So what am I missing? The only other option I can think of would be: `pex -r requests -o client.pex` & then write a script that calls `client.py` from the pex environment (i.e., `./client.pex client.py -h` or whatever), and bundle the pex file, `client.py`, and the script together. But that seems like a misuse of the tool, at best. Alternatively/additionally: is there any mailing list/help source for pex? It seems like a great project, but I've not been able to find many resources out there, which is why I'm turning to you guys. (Why not just install pip/requests on the target machine? Because this is part of an effort to automate provisioning of a bunch of machines.) (Why not use pants? Because literally all we need is requests, and that seems like overkill.) (Also: anyone who's planning on chewing me out about formatting: I TRIED posting by email to [email protected], but it wouldn't let me. Sorry for the extra whitespace.) -- https://mail.python.org/mailman/listinfo/python-list
Re: Pex import problems
On Tuesday, October 21, 2014 12:05:00 PM UTC-4, Chris Angelico wrote: > On Wed, Oct 22, 2014 at 2:34 AM, Sam Raker wrote: > > > (Also: anyone who's planning on chewing me out about formatting: I TRIED > > posting by email to [email protected], but it wouldn't let > > me. Sorry for the extra whitespace.) > That's because that isn't the mailing list's name. Sign up here: > https://mail.python.org/mailman/listinfo/python-list > ChrisA Thank you for your help. -- https://mail.python.org/mailman/listinfo/python-list
Pex import problems
Hi all, I'm trying to use Pex (http://pex.readthedocs.org/en/latest/index.html) to include requests in a little script to ping a server from a machine that doesn't come with pip (or much of anything, really) installed. I'm running into problems outputting a pex file that depends on a local script. I've got a command-line file, `client.py`, that can be called with a few command-line options. I can run `pex -r requests -o client.pex -- client.py`, but when I try `./client.pex -h` I get an error about "no such file or directory: '-h'". Ok, next attempt: `pex -r requests -o client.pex -e client` --> "ImportError: No module named client". I dug around in the code a bit, and from what I can tell, `-e FOO` boils down to `__import__(FOO)`, which I can do, both from the interpreter and from a test script. So what am I missing? The only other option I can think of would be: `pex -r requests -o client.pex` & then write a script that calls `client.py` from the pex environment (i.e., `./client.pex client.py -h` or whatever), and bundle the pex file, `client.py`, and the script together. But that seems like a misuse of the tool, at best. Alternatively/additionally: is there any mailing list/help source for pex? It seems like a great project, but I've not been able to find many resources out there, which is why I'm turning to you guys. (Why not just install pip/requests on the target machine? Because this is part of an effort to automate provisioning of a bunch of machines.) (Why not use pants? Because literally all we need is requests, and that seems like overkill.) -- https://mail.python.org/mailman/listinfo/python-list
