Re: Does hashlib support a file mode?
wow, tx y'all! I forgot to mention that hashlib itself is not required; I could also use Brand X. But y'all agree that blocking up the file in python adds no overhead to hashing each block in C, so hashlib in a loop it is! -- http://mail.python.org/mailman/listinfo/python-list
Re: Does hashlib support a file mode?
Tx, all!. But... > For example I use this function to copy a stream and return a SHA512 and > the output streams size: > > def write(self, in_handle, out_handle): > m = hashlib.sha512() > data = in_handle.read(4096) > while True: > if not data: > break > m.update(data) > out_handle.write(data) > data = in_handle.read(4096) > out_handle.flush() > return (m.hexdigest(), in_handle.tell()) The operation was a success but the patient died. My version of that did not return the same hex digest as the md5sum version: def file_to_hash(path, m = hashlib.md5()): with open(path, 'r') as f: s = f.read(8192) while s: m.update(s) s = f.read(8192) return m.hexdigest() You'll notice it has the same control flow as yours. That number must eventually match an iPad's internal MD5 opinion of that file, after it copies up, so I naturally cannot continue working this problem until we see which of the two numbers the iPad likes! -- http://mail.python.org/mailman/listinfo/python-list
Re: Does hashlib support a file mode?
> - Open the file in binary mode. I had tried open(path, 'rb') and it didn't change the "wrong" number. And I added --binary to my evil md5sum version, and it didn't change the "right" number! Gods bless those legacy hacks that will never die, huh? But I'm using Ubuntu (inside VMWare, on Win7, on a Core i7, because I rule), so that might explain why "binary mode" is a no-op. > - Do the usual dance for default arguments: > def file_to_hash(path, m=None): > if m is None: > m = hashlib.md5() Not sure why if that's what the defaulter does? I did indeed get an MD5-style string of what casually appeared to be the right length, so that implies the defaulter is not to blame... -- http://mail.python.org/mailman/listinfo/python-list
Re: Does hashlib support a file mode?
> >> def file_to_hash(path, m=None): > >> if m is None: > >> m = hashlib.md5() > The first call will give you the correct checksum, the second: not. As the > default md5 instance remembers the state from the previous function call > you'll get the checksum of both files combined. Ouch. That was it. Python sucks. m = md5() looks like an initial assignment, not a special magic storage mode. Principle of least surprise fail, and principle of most helpful default behavior fail. -- http://mail.python.org/mailman/listinfo/python-list
Re: Does hashlib support a file mode?
On Jul 6, 11:42 am, Andrew Berg wrote: > On 2011.07.06 12:38 PM, Phlip wrote:> Python sucks. m = md5() looks like an > initial assignment, not a > > special magic storage mode. Principle of least surprise fail, and > > principle of most helpful default behavior fail. > > func() = whatever the function returns > func = the function object itself (in Python, everything's an object) > > Maybe you have Python confused with another language (I don't know what > exactly you mean by initial assignment). Typically one does not need > more than one name for a function/method. When a function/method is > defined, it gets created as a function object and occupies the namespace > in which it's defined. If I call m = md5() twice, I expect two objects. I am now aware that Python bends the definition of "call" based on where the line occurs. Principle of least surprise. -- http://mail.python.org/mailman/listinfo/python-list
Re: Does hashlib support a file mode?
On Jul 6, 1:25 pm, Carl Banks wrote: > We already know about this violation of the least surprise principle; most of > us acknowledge it as small blip in an otherwise straightforward and clean > language. Here's the production code we're going with - thanks again all: def file_to_hash(path, hash_type=hashlib.md5): """ Per: http://groups.google.com/group/comp.lang.python/browse_thread/thread/ea1c46f77ac1738c """ hash = hash_type() with open(path, 'rb') as f: while True: s = f.read(8192) # CONSIDER: io.DEFAULT_BUFFER_SIZE if not s: break hash.update(s) return hash.hexdigest() Note the fix also avoids comparing to None, which, as usual, is also icky and less typesafe! (And don't get me started about the extra lines needed to avoid THIS atrocity! while s = f.read(8192): hash.update(s) ;) -- http://mail.python.org/mailman/listinfo/python-list
Re: Does hashlib support a file mode?
> On 2011.07.06 06:16 PM, Steven D'Aprano wrote:> Phlip wrote: > > > > Note the fix also avoids comparing to None, which, as usual, is also > > > icky and less typesafe! > > > "Typesafe"? Are you trying to make a joke? No, I was pointing out that passing a type is more ... typesafe. -- http://mail.python.org/mailman/listinfo/python-list
Re: Does hashlib support a file mode?
On Jul 7, 6:24 am, Andrew Berg wrote: > On 2011.07.07 08:11 AM, Phlip wrote:> No, I was pointing out that passing a > type is more ... typesafe. > > None is a type. I never said it wasn't. -- http://mail.python.org/mailman/listinfo/python-list
Re: Programming tips :-)
On Jul 7, 11:36 am, Andrew Berg wrote: > On 2011.07.07 12:22 PM, Martin Schöön wrote:> I just found the following url > in my archives at work and > > thought you might enjoy it: > >http://thc.org/root/phun/unmaintain.html > > That's awesome. That's "How To Write Unmaintainable Code" - a venerable classic. Compare these: http://c2.com/cgi/wiki?HowToPissOffYourPair http://c2.com/cgi/wiki?HelpSourceForgeSuck -- http://mail.python.org/mailman/listinfo/python-list
Re: Does hashlib support a file mode?
> I worded that poorly. None is (AFAIK) the only instance of NoneType, but > I should've clarified the difference.> The is operator does not compare > types, it compares instances for identity. None is typesafe, because it's strongly typed. However, what's even MORE X-safe (for various values of X) is a method that takes LESS for its arguments. That's why I switched from passing an object to passing a type, because the more restrictive argument type is more typesafe. However, the MOST X-safe version so far simply passes a string, and uses hashlib the way it designs to be used: def file_to_hash(path, hash_type): hash = hashlib.new(hash_type) with open(path, 'rb') as f: while True: s = f.read(8192) if not s: break hash.update(s) return hash.hexdigest() -- http://mail.python.org/mailman/listinfo/python-list
Re: Does hashlib support a file mode?
On Jul 8, 12:42 am, Steven D'Aprano wrote: > Phlip wrote: > >> I worded that poorly. None is (AFAIK) the only instance of NoneType, but > >> I should've clarified the difference.> The is operator does not compare > >> types, it compares instances for identity. > > > None is typesafe, because it's strongly typed. > > Everything in Python is strongly typed. Why single out None? You do understand these cheap shots are bad for conversations, right? I didn't single out None. When did you stop raping your mother? -- http://mail.python.org/mailman/listinfo/python-list
Re: CI and BDD with Python
On Jul 8, 9:36 pm, Stefan Behnel wrote: > mark curphey, 09.07.2011 01:41: > > > And for CI having been using Hudson for a while, any real advantages in a > > Python / Django world for adopting something native like Trac and one of > > the CI plugins like Bitten? I'm kind'a partial to Morelia for BDD. Don't be fooled by Ruby's RSpec - it's _not_ "BDD". In my exalted opinion. "BDD" means "your customer gives you requirements as sentences, and you make them into executable statements." That's what Cucumber does, which Morelia learns from. And BDD and CI are orthogonal. BDD should be part of a complete TDD test suite, and your CI tool should run that. I still like CruiseControl.rb - even though it has bugs when it sees too many git integrations. Hudson had way too many features, and CCrb mildly presumes you know how to operate its .cruise/projects folder manually! -- http://mail.python.org/mailman/listinfo/python-list
Re: CI and BDD with Python
On Jul 9, 7:39 pm, mark curphey wrote: > Thanks. FWIW I played with a bunch (Freshen, Morelia, Lettuce) Morelia is "undermaintained" because it's finished. It attaches to any pre-existing TestCase-style test runner, hence there's nothing to maintain! Packages like Lettuce rebuild the entire TestCase back-end just to change the front end. That forces its maintainer to then do the Red Queen thing, and constantly compete with all other test runners just to stay in place. Props for the effort, though..! -- http://mail.python.org/mailman/listinfo/python-list
Re: Morelia for BDD in Python (was: CI and BDD with Python)
On Jul 9, 8:38 pm, Ben Finney wrote: > Phlip writes: > > On Jul 9, 7:39 pm, mark curphey wrote: > > > > Thanks. FWIW I played with a bunch (Freshen, Morelia, Lettuce) > > > Morelia is "undermaintained" because it's finished. It attaches to any > > pre-existing TestCase-style test runner, hence there's nothing to > > maintain! > > It looks good! But it's not yet in Debian :-( Tx - I never added anything to a distro before! But..! 'sudo pip install morelia' just worked for me, on Ubuntu. I don't think a python-morelia aptitude package would add any value. Such test rigs shall never have any embedded C code or other shenanigans. If I needed to think of a feature to add, it would be P notation in the regular expressions, to then enforce the names of the matching arguments. But this is fluff; real programmers can do without it. If I worked closer to the center of the BDD thought leadership I'd know what else to add... -- http://mail.python.org/mailman/listinfo/python-list
Re: Morelia for BDD in Python (was: CI and BDD with Python)
> -- > \ “That's the essence of science: Ask an impertinent question, | > `\ and you're on the way to the pertinent answer.” —Jacob | > _o__) Boronowski, _The Ascent of Man_, 1976 | > Ben Finney That nose keeps reminding me of the start of one of the Pirates of the Caribbean movies... -- http://mail.python.org/mailman/listinfo/python-list
Re: Morelia for BDD in Python
> I think it would add great value, since without it I'm unlikely to > bother using Morelia in any project. The maintenance burden is too high > to keep adding dependencies that come from a distinct dependency system > outside my OS. pip freeze! Specifically, we already added pip freeze and virtualenv support to our project's fab file... > There's no "pip uninstall", though. I can see that would matter to projects you would want to uninstall, but not Morelia... -- http://mail.python.org/mailman/listinfo/python-list
Re: Morelia for BDD in Python
Two of my feature requests for Morelia: - integrate with the test runner (nose etc.) to provide one dot . per passing step - insert a long multi-line abstract string (typically XML) with inside [[CDATA-style escaping tags - the ability to stub a step as - the ability to pass a | delimited | table into a step as an argument containing an array, instead of unrolling the table into multiple calls to one step - a rapid conversion to an HTML report, with folding blocks, as an instant project documentation. Lack of the second option is why we _didn't_ use M for the BDD test runner on our latest project. (The onsite customer is an XML-freak, AND the lead architect until I can manage to retire him upstairs!;) But if I could put those four in, then write a disposable script that converted our XML "project definition" file back into Morelia-Cucumber- Gherkin notation, I'd have Morelia back in our project! -- http://mail.python.org/mailman/listinfo/python-list
Re: "Python Wizard," with apologies to The Who
> That modeling and sim guy > Sure codes some mean Python! C-; And he changes key on the fly, too! -- http://mail.python.org/mailman/listinfo/python-list
Re: "Python Wizard," with apologies to The Who
> That's pretty funny. I knew what it would be even when I saw the cut-off > subject line, and I am too young to remember it. > > Carl Banks TTTO "[She put the lime in the] Coconut": Brother wrote a database, he finish it on time His sister add requirements, refactor every line She change design in the database, she mix it all up She change design in the database, she mix it all up She change design in the database, she mix it all up She change design in that database, she called the doctor, woke him up, Sayin' "Doctor, now I got to pay my dues, I say, Doctor, to debug away my blues, I say, Doctor, such a big change has to break, I say, Doctor! I must'a made a bug mistake!" "Now let me get this straight, You change the design in the database, mix things all up You change the design in the database, mix it all up, You change the design in the database, mix it all up..." http://c2.com/cgi/wiki?SheChangeDesignInTheDatabase -- http://mail.python.org/mailman/listinfo/python-list
Re: I am fed up with Python GUI toolkits...
On Jul 20, 10:32 am, rantingrick wrote: > Steven, you have no buisness offering advice on Tkinter since you > yourself have proclaimed that YOU NEVER used the module and never > will. Stick to what you know please. Allow me. Tkinter sucks because it looks like an enfeebled Motif 1980s dawn-of- GUIs scratchy window with grooves and lines everywhere. Tkinter is awesome because you can nest anything inside anything else, and it has an elaborate & extendable properties system. Oh, and you can TDD it. Unlike some more "modern" GUIs I could mention... -- http://mail.python.org/mailman/listinfo/python-list
Re: I am fed up with Python GUI toolkits...
On Jul 20, 3:13 pm, sturlamolden wrote: > On 20 Jul, 22:58, Phlip wrote: > > > Tkinter sucks because it looks like an enfeebled Motif 1980s dawn-of- > > GUIs scratchy window with grooves and lines everywhere. > > The widget set is limited compared to GTK or Qt, though it has the > most common GUI controls, and it does not look that bad with the > recent ttk styling (it actually doesn't look like Motif anymore). But > it does not have a good GUI builder (that I know of). Oh, and you can TDD it, too... -- http://mail.python.org/mailman/listinfo/python-list
Changing subject sucks. Re: I am fed up with Python GUI toolkits...
On Jul 20, 6:17 pm, rantingrick wrote: > RE: *Ben Finney changes thread subject* > > Please everyone, do not change the subject of someone's thread because > it's considered rude. Thank you. No it isn't. Rambling off on a new topic under the wrong subject is rude. -- http://mail.python.org/mailman/listinfo/python-list
Re: Snippet: The leanest Popen wrapper
> flatten() being defined as...? Python Cookbook recipe 4.6 def flatten(sequence): # CONSIDER: Reconcile with utils... for item in sequence: if isinstance(item, (list, tuple)): for subitem in flatten(list(item)): yield subitem else: yield item >> shell= True, > I would strongly encourage you to avoid shell=True. You really don't > want to have to worry about doing proper shell escaping yourself. Tx for helping me avoid reading up on it. I just copied it in. I keep getting "fab not found" etc. when running 'fab command' thru it. So then I ditch to os.system(). The long-term solution would be 'bash', '-c', 'yack yack yack' if you want truly shelly things! -- Phlip http://c2.com/cgi/wiki?ZeekLand -- http://mail.python.org/mailman/listinfo/python-list
filename of calling function?
Consider these two python modules: aa.py def a(): print '?' bb.py import aa def bb(): aa.a() bb() How do I make the print line emit the filename of bb.py? (It could be anything.) I am currently playing with sys.exc_info, but it seems to only emit the stack between the raise and the except. Could be pilot error, of course. Thanks for any help! -- Phlip http://c2.com/cgi/wiki?ZeekLand -- http://mail.python.org/mailman/listinfo/python-list
Re: filename of calling function?
On Nov 28, 8:19 am, Phlip wrote: > Consider these two python modules: > > aa.py > > def a(): > print '?' > > bb.py > import aa > > def bb(): > aa.a() > > bb() > > How do I make the print line emit the filename of bb.py? (It could be > anything.) try: raise None except: import sys from traceback import extract_tb, extract_stack frame = sys.exc_info()[2].tb_frame.f_back calling_file = extract_stack(frame, 2)[1][0] -- http://mail.python.org/mailman/listinfo/python-list
Re: filename of calling function?
On Nov 28, 9:04 am, Joel Davis wrote: > > try: > > raise None > > except: > > import sys > > from traceback import extract_tb, extract_stack > > frame = sys.exc_info()[2].tb_frame.f_back > > calling_file = extract_stack(frame, 2)[1][0] > > code works perfectly except on my system both the indexes need to be 0 > (eg: "extract_stack(frame, 2)[0][0]") I thought the 0 was myself, 1 my caller, etc. But tx for trying it -- http://mail.python.org/mailman/listinfo/python-list
Re: Question on Python as career
joy99 wrote: I have developed the following toolkits: (i) A web based crawler; (ii) A Bayesian classifier; (iii) One NER engine; (iv) One XML parser; (v) One PoS Tagger; (vi) One Parser based on CRF; (vii) One MLE training system; (viii) One Spell Checker; (ix) One Transliteration System; I have developed them either in Python2.5 and Python2.6. After I complete my Post Doctoral which may be only 2-3 months away, with this knowledge can I join IT? All your items are computer science. IT is about software engineering. That means _avoiding_ new research in preference for efficiently implementing business solutions. Or Do I have to learn anything new? Test Driven Development. Active Record (ORM models) HTML & webby technologies platforms & deployment issues GNU, open source, and version controlling Behavior Driven Development Are there any India based opportunities- as I checked Python job board it is very less. Ideally, IT should get the job done using a soft language like Python, Ruby, or Lua. IT should not waste its time using a hard language like C++. That is for system programming - making the modules that IT reuses. If I get anything after completing my Post Doc with present base of knowledge what profiles I may expect? How about videogames? They always need hard algorithms & computer science. -- Phlip http://c2.com/cgi/wiki?ZeekLand -- http://mail.python.org/mailman/listinfo/python-list
Re: combinatorics via __future__ generators
Awesome thanks - but: > from itertools import imap,product Do we have a version for Python2.5? I have to support an older server here; can't install a newer python on it... -- http://mail.python.org/mailman/listinfo/python-list
mock any instance
Pythonistas: One important design principle is "construction encapsulation". That's where nobody creates anything, they always use things passed to them. Without this principle, when I need to mock the encapsulated item, some mock libraries provide an "any instance" facility. For example, here's a mock on one method of only one object: object = Thang() object.method = Mock() object.method() # <-- calls the mock, not the real method I need to mock the method on any instance spawned by a given class: Thang.method = MockAnyInstance() object = Thang() object.method() # <-- calls the mock, not the real method That will avoid "cutting a hole in the bulkhead" just to get to the 'object = Thang()' line, to let me spoof out the Thang. Does anyone have any idea how to do that with the good-old Mocker here? http://python-mock.sourceforge.net/ if I should use a different mocker, I would prefer it behave like that mock, for aesthetic reasons, and also to avoid the need to replace all our existing Mocks with a new one, following the rule that we should not use too many classes to do the same thing (DRY). -- Phlip http://c2.com/cgi/wiki?ZeekLand -- http://mail.python.org/mailman/listinfo/python-list
how to register with pypi
Pythonistas: I'm stuck on the "PGP Key ID". When I whip out my trusty Ubuntu and run pgp -kg, I get a 16-digit "DSA / EIGamal" key. When I enter it into http://pypi.python.org/pypi?%3Aaction=register_form , I get a helpful "PGP Key ID is invalid". Should I try a key of some other algorithm? -- Phlip http://c2.com/cgi/wiki?ZeekLand -- http://mail.python.org/mailman/listinfo/python-list
Re: how to register with pypi
Martin v. Loewis wrote: I'm stuck on the "PGP Key ID". When I whip out my trusty Ubuntu and run pgp -kg, I get a 16-digit "DSA / EIGamal" key. When I enter it into http://pypi.python.org/pypi?%3Aaction=register_form , I get a helpful "PGP Key ID is invalid". Should I try a key of some other algorithm? If you merely try to register with PyPI, you don't need to provide a PGP key id at all. I want to upload a crypto library I invented. That's a joke. But I want to upload a library. The key ID should be an eight-digit string, such as EA5BBD71 (i.e. a 32-bit key ID). pretend I was someone who had never ever used PGP before. pgp -kg, then what? -- http://mail.python.org/mailman/listinfo/python-list
Re: how to register with pypi
If you have never used PGP before, you *really* shouldn't register a PGP key ID in PyPI. I suppose your key doesn't have any counter signatures, anyway. Nope, thanks, I'm already in. The pypi page could mark the field "optional". I just associated it, conceptually, with the Github SSH key, and with passwordless login in general, and assumed it was required... -- http://mail.python.org/mailman/listinfo/python-list
how to register with pypi - no such setup.py
And the next question in the series - how to make sure the resulting package has a setup.py file? The basic steps are... - build a python package - create a minimal setup.py - (github it, natch) - throw it at pypi with: python setup.py bdist upload - attempt to install it with: sudo pip install my_package and get this: Downloading/unpacking my_package ... IOError: [Errno 2] No such file or directory: '.../setup.py' So the irony is if I had to use setup.py to build the MyPackage..tar.gz, why isn't it inside it? Any tips? (the actual package name is censored because I don't need people finding this if they google for that!;) -- http://mail.python.org/mailman/listinfo/python-list
how to register with pypi - no such setup.py
And the next question in the series - how to make sure the resulting package has a setup.py file? The basic steps are... - build a python package - create a minimal setup.py - (github it, natch) - throw it at pypi with: python setup.py bdist upload - attempt to install it with: sudo pip install my_package and get this: Downloading/unpacking my_package ... IOError: [Errno 2] No such file or directory: '.../setup.py' So the irony is if I had to use setup.py to build the MyPackage..tar.gz, why isn't it inside it? Any tips? (the actual package name is censored because I don't need people finding this if they google for that!;) (and this is a repost because I can't see my admittedly off-topic question on the newsgroup) -- http://mail.python.org/mailman/listinfo/python-list
Re: how to register with pypi - no such setup.py
On Dec 24, 3:32 am, "Martin v. Loewis" wrote: > > Any tips? > > A binary distribution won't have a setup.py, because > you can install it by other means (such as Windows Installer), > instead of running setup.py > > What you want is a source distribution (sdist). Thanks. Yes, this is prob'ly documented somewhere. Now my next problem - how to get pypi.python.org to stop burning up version numbers each time I test this? -- http://mail.python.org/mailman/listinfo/python-list
Re: how to register with pypi - no such setup.py
On Dec 26, 6:01 am, "Martin v. Loewis" wrote: > > Now my next problem - how to get pypi.python.org to stop burning up > > version numbers each time I test this? > > I don't speak English well enough to understand what "to burn up" > means - to my knowledge, PyPI does no such thing. I don't know how to test pypi on my own notebook. Each time I change setup.py or something, if I want to test my change, I have to boost the version number, and then use sdist upload to push a new version to the server. This means I am using up perfectly good version numbers. If I don't change the number, I get a condescending message "Upload failed (400): A file named "Morelia-0.0.10.tar.gz" already exists for Morelia-0.0.10. To fix problems with that file you should create a new release." I have no alternative, to fix bugs in PyPi, _not_ in "that file", but to continue burning up version numbers that nobody cares about. The message is condescending because I am aware of the reason we version packages, and the message is _not_ helping me apply that reason! -- http://mail.python.org/mailman/listinfo/python-list
Re: how to register with pypi - no such setup.py
> I have no alternative, to fix bugs in PyPi, _not_ in "that file", but > to continue burning up version numbers that nobody cares about. The > message is condescending because I am aware of the reason we version > packages, and the message is _not_ helping me apply that reason! Aaand I just found the Remove button, so the complaint is down to a misleading error message! -- http://mail.python.org/mailman/listinfo/python-list
Re: how to register with pypi - no such setup.py
On Dec 26, 4:24 pm, Stefan Krah wrote: > It is quite reasonable that changed archives with the same version number > are not accepted. Very helpful, not condescending. The message helps you remember to bump your version number. Try: "Please either increment your version number, or use your Package Editing page to delete the release" The current message implies I have problems with my library, but don't know that problems with libraries are what version numbers are for... -- http://mail.python.org/mailman/listinfo/python-list
Re: Thanks for the help not given :)
To the OP - adding "... because Python sucks" to your subject lines will increase the quantity of answers - but possibly not the quality. You can also learn a little about good questions by answering others's here. And I hope you answered your questions here, if no one else did, to avoid dead search trails in the archives. You learn by teaching! As for me, my questions are usually some combination of hopelessly retarded and beyond the blue sky envelope that I take pity on anyone even reading them, less answering them... Jon Clements wrote: You have a bear that likes a Python? The one I have just keeps going on about Piglet and eating my honey reserves... http://zeekland.zeroplayer.com/Pigleg_Too/1 -- http://mail.python.org/mailman/listinfo/python-list
change an exception's message and re-raise it
Pythonistas:
I need to do this:
try:
deep_arcane_layer()
except e:
e.message = 'the deep arcane layer says: ' + e.message
raise e
The point is I need to augment that layer's exceptions with extra
information that I know about that layer.
I naturally cannot use the argless version of 'raise', because it only
re-raises whatever exception object is currently in play - and it
appears to be read-only or locked or something.
I also should not do this...
raise Exception('blah ' + e.message)
...because that stripped off the exception type itself, and higher
layers need to know this.
My question is a common pattern in layered architectures, where
exceptions get decorated with extra info as they bubble up from the
engine room to the bridge. Any ideas?
--
Phlip
http://zeekland.zeroplayer.com/The_Elaborate_Art_of_Play_Part_1/1
--
http://mail.python.org/mailman/listinfo/python-list
Re: change an exception's message and re-raise it
On Dec 31 2009, 4:30 pm, Steven D'Aprano wrote:
> ... 1/0
> ... except ZeroDivisionError, e:
> ... e.args = e.args + ('fe', 'fi', 'fo', 'fum')
> ... raise
When I added print e.args it showed the old args. Maybe I was trying
too hard - this is why I said e seemed locked or something.
This started working:
new_exception = self.format_fault(e.args[0])
e.args = (new_exception,) + (e.args[1:])
raise
May I ask if args always has more than one entry? I need to bypass the
silly "'tuple' object does not support item assignment" issue...
--
http://mail.python.org/mailman/listinfo/python-list
Re: change an exception's message and re-raise it
On Dec 31 2009, 4:30 pm, Steven D'Aprano wrote:
> For the record you can get the exception type from type(e):
>
> raise type(e)("whatever you want")
>
> but that creates a new exception, not re-raising the old one.
Except if a type constructs with some other number of arguments,
apparently...
--
http://mail.python.org/mailman/listinfo/python-list
Re: How to validate the __init__ parameters
Steve Holden wrote: What's the exact reason for requiring that a creator argument be of a specific type? So operations on the instances don't go wrong? Well, why not just admit that we don't have control over everything, and just *let things go wrong* when the wrong type is passed? Because some interfaces are "public", meaning visible within their own little arena of modules, and some interfaces are "published", meaning visible to other packages. Encapsulation is hierarchical - this is just a "small things go inside big things" situation. The higher an interface's level, the more "published" it is. Published interfaces should fail as early and clearly as possible if they are going to fail. The obvious example here is an interface that fails and prints a message telling a newbie how to call the package the right way. But that newbie could be you! (And don't forget the wall-to-wall unit tests, too;) -- Phlip http://c2.com/cgi/wiki?MoreliaViridis -- http://mail.python.org/mailman/listinfo/python-list
Where's a DOM builder that uses the Builder Pattern to ... build DOMs?
Not Hyp:
I hope I'm wrong, but seems that DOMBuilder, found among the various
xml.dom packages, cannot build DOM like this:
var html = DomBuilder.apply();
var form = html.FORM(
html.DIV(
html.INPUT({type : 'text', name : 'email'}),
html.INPUT({type : 'text', name : 'password'}),
html.INPUT({type : 'submit'}),
)
);
Do anyone know any good DOM builder packages that do build DOM good
like a DOM builder should?
--
Phlip
http://zeekland.zeroplayer.com/Uncle_Wiggilys_Travels/1
--
http://mail.python.org/mailman/listinfo/python-list
Re: Where's a DOM builder that uses the Builder Pattern to ... build DOMs?
On Jan 5, 12:16 am, Stefan Behnel wrote: > Note that there are tons of ways to generate HTML with Python. Forgot to note - I'm generating schematic XML, and I'm trying to find a way better than the Django template I started with! -- http://mail.python.org/mailman/listinfo/python-list
Re: twenty years ago Guido created Python
On Dec 31 2009, 2:06 pm, Steve Howell wrote: > Python is a truly awesome programming language. Not only is Guido a > genius language designer, but he is also a great project leader. What > an accomplishment. Congratulations to everybody who has contributed > to Python in the last two decades! The more languages you learn before getting to Smalltalk, the more awesome Smalltalk will be for you. -- Phlip -- http://mail.python.org/mailman/listinfo/python-list
please help shrink this each_with_index() implementation
Hypo Nt: def each_with_index(seq): index = 0 result = [] for item in seq: result.append([item, index]) index += 1 return result My Pythonic sequencing skills are obviously feeble. Can anything think of a way to write that in fewer lines? -- Phlip http://c2.com/cgi/wiki?MoreliaViridis -- http://mail.python.org/mailman/listinfo/python-list
Re: please help shrink this each_with_index() implementation
> > My Pythonic sequencing skills are obviously feeble. Can anything think > > of a way to write that in fewer lines? Thanks, all! > Couldn't you just use the built-in enumerate() to replace the whole thing? Because that would involve, like, reading an entire Python book just to locate that method? GMAB I'm too busy writing high-end Django via TDD & BDD! C-: -- Phlip http://zeekland.zeroplayer.com/Pigleg_Too/1 -- http://mail.python.org/mailman/listinfo/python-list
Re: please help shrink this each_with_index() implementation
On Jan 5, 1:10 pm, Antoine Pitrou wrote: > http://docs.python.org/library/functions.html > > Don't forget that the Python documentation is rich and structured. > And good luck. Does it say how to convert a string containing either an integer representation, or something alphabetic, into an integer, or a zero, in like 1 method call? (No except: ?) Nothing personal, but I'm finding the super-hard stuff very facile & tractable, and the easy stuff absurdly hard around here... -- http://mail.python.org/mailman/listinfo/python-list
Re: please help shrink this each_with_index() implementation
> > Does it say how to convert a string containing either an integer
> > representation, or something alphabetic, into an integer, or a zero, in
> > like 1 method call? (No except: ?)
>
> If you mean something like this:
>
> >>> int('153')
>
> 153
The point: int('') or int('something') both throw an error. In
general, this is hand-holding, but in specific I don't think the "rich
and structured" documentation will cover how to beat a 0 out of it in
less than 3 lines. So I will persist in my idiotic questions here!
> Then perhaps you should work through the tutorial to learn the basics.
They will tell me how to use except: (which is a good example why a
program should not use exceptions for its normal control flow if at
all possible).
Please, please, please save your newbie admonitions for those who
qualify!
--
http://mail.python.org/mailman/listinfo/python-list
Re: Exception as the primary error handling mechanism?
Peng Yu wrote:
> Otherwise, could some python expert explain to me why exception is
> widely used for error handling in python? Is it because the efficiency
> is not the primary goal of python?
It's not about efficiency, it's about making assumptions for the
programmer about what kind of rigor they need.
Why can't int('nonnumeric') return None?
Why can't a Django Record.objects.get(pk=-1) return a None? That's
what it's for.
(A related question - why can't I just go 'if record = method(): use
(record)'. Why extra lines just to trap and assign the variable before
using it?)
There are workarounds that sometimes benefit the code. In the case of
collections, like recordsets, you might be better off using for ... all
():
Then your controlled block efficiently does not happen if it saw no
records. "Efficiently" in terms of programmer complexity - the number
and meaning of lines that a programmer must comprehend.
And why can't Record.objects.get(pk='nonnumeric') return None?
Because, of course, deep inside it calls int(). I can't simplify the
calling code, and rely on garbage-in-None-out, because Python decided
which simplifications I should avoid with self-righteous indignation.
The Samurai Principle (return victorious, or not at all) is very
useful, sometimes. But other times it just prematurely depletes your
supply of Samurai...
--
Phlip
http://zeekland.zeroplayer.com/
--
http://mail.python.org/mailman/listinfo/python-list
Re: Exception as the primary error handling mechanism?
On Jan 5, 5:01 pm, Chris Rebert wrote:
> > Why can't int('nonnumeric') return None?
>
> Errors should never pass silently.
You are saying I, as the programmer, cannot decide what is an error
and what is a pass-thru. The decision is made for me. (Yes yes I can
write int_or_None(), etc...)
Here's a super easy example:
{ 42: 'forty two' }.get(41, None)
Because I can supply a default, I can decide what is an error and what
is .
Now the equivalent in a language that does not enjoy this false "Zen":
{ 42: 'forty two' }[41] # returns None
{ 42: 'forty two' }.fetch(41, None) # ibid
{ 42: 'forty two' }.fetch(41) # raises an exception
The quicky validation is available if I _request_ it.
> Quibbling over a mere one more line of code (or writing one short
> function) seems a bit petty.
Because that "Zen of Python" is an empty sophistry that forces me to
add a "mere one more line of code" over and over again...
> > (A related question - why can't I just go 'if record = method(): use
> > (record)'. Why extra lines just to trap and assign the variable before
> > using it?)
>
> I believe that's disallowed so as to prevent the subtle bugs seen in C
> code which result from when someone makes a typo and omits the second
> "=" in their `if foo == bar():` test.
Don't prevent me from using a technique just because others had
trouble with it.
And if bar() == foo is the superior technique anyway, because the ==
happens in chronological and lexical order after the bar() call.
--
http://mail.python.org/mailman/listinfo/python-list
Re: unittest inconsistent
On Jan 5, 4:14 pm, Matt Haggard wrote: > Can anyone tell me why this test fails? > > http://pastebin.com/f20039b17 > > This is a minimal example of a much more complex thing I'm trying to > do. I'm trying to hijack a function and inspect the args passed to it > by another function. > > The reason the 'Tester' object has no attribute 'arg1' is because > "self" still refers to the object made for testA. I hope someone else can spot the low-level reason... ...but why aren't you using http://pypi.python.org/pypi/mock/ ? Look up its patch_object facility... -- http://mail.python.org/mailman/listinfo/python-list
Re: Exception as the primary error handling mechanism?
> Errors should never pass silently. > Unless explicitly silenced. > -- The Zen of Python (http://www.python.org/dev/peps/pep-0020/) "The person who says it cannot be done should never interrupt the person doing it" -- http://mail.python.org/mailman/listinfo/python-list
Re: Exception as the primary error handling mechanism?
On Jan 5, 8:49 pm, Steven D'Aprano wrote: > > (A related question - why can't I just go 'if record = method(): use > > (record)'. Why extra lines just to trap and assign the variable before > > using it?) > > Because that idiom is responsible for probably the most common error in C > of all, at least one of the most common errors. Thank goodness Python > forbids such a dangerous construct. switching = for == is the "most common error in C"? I can't tell if you are joking. -- http://mail.python.org/mailman/listinfo/python-list
Re: Exception as the primary error handling mechanism?
On Jan 5, 10:54 pm, Benjamin Kaplan wrote:
> {41: None}[41] ?
>
> In cases where None is a valid result, you can't use it to signal failure.
Asked and answered. You change the "sentinel" in .fetch to something
else.
But y'all keep on defending the language making your programming
decisions for you!
--
http://mail.python.org/mailman/listinfo/python-list
Re: Exception as the primary error handling mechanism?
Steve Holden wrote: y'all just keep defending the approach to programming that *you* think is best. Speak for yourself... -- http://mail.python.org/mailman/listinfo/python-list
Re: please help shrink this each_with_index() implementation
Nobody wrote: On Tue, 05 Jan 2010 19:46:01 -0800, alex23 wrote: They will tell me how to use except: (which is a good example why a program should not use exceptions for its normal control flow if at all possible). Really? Magic functions that coerce and eat errors are a better coding technique than exceptions and explicit handling? What kool-aid have you been drinking? Maybe he's doing it for a living? Contract programming seems to work on the basis that the ultimate requirement is for the client to hand over the money. If, at that point, the program is still full of bugs, you get to charge extra for "upgrades". Uh, no, right now I'm working with the long-term goal of creating useful modules that sustain us equitably. Writing robust software from the outset puts you at a competitive disadvantage to those who understand how the system works. And I, not my language, should pick and chose how to be rigorous. The language should not make the decision for me. -- http://mail.python.org/mailman/listinfo/python-list
Re: Exception as the primary error handling mechanism?
On Jan 6, 10:23 am, Lie Ryan wrote: > On 1/7/2010 3:41 AM, Phlip wrote: > > > Steve Holden wrote: > > >> y'all just keep defending the approach to programming that > >> *you* think is best. > > > Speak for yourself... > > Everyone speaks for themselves, is that a problem? Of course not. I was pointing out that Steve is telling me not to force my programming opinions on everyone... ...while defending Python enforcing programming opinions on everyone. And now, if everyone will excuse me, I have to get back to writing a unit-test-to-code ratio of 2:1. Have fun being rigorous, everyone! -- http://mail.python.org/mailman/listinfo/python-list
Re: Where's a DOM builder that uses the Builder Pattern to ... build DOMs?
On Jan 7, 5:36 am, Stefan Behnel wrote: > Well, then note that there are tons of ways to generate XML with Python, > including the one I pointed you to. from lxml.html import builder as E xml = E.foo() All I want is "", but I get "AttributeError: 'module' object has no attribute 'foo'". A peek at dir(E) shows it only has HTML tags, all hard coded. So how to get it to generate any random XML tag my clients think of? I will write this myself with __getattr__ etc, if I can't find it, because the permissive & expressive builder pattern I'm after would be very ... permissive & expressive. All I want is a library that reads my mind!!! Is that too much to ask??? (Unless if the library insists on throwing a NullMind exception, on principle...) -- Phlip http://twitter.com/Pen_Bird -- http://mail.python.org/mailman/listinfo/python-list
Re: Fundamental Function Question (beginner)
MRAB wrote: Scott wrote: for prtnmS in open(portfpth): prtnmS = prtnmS.rstrip() There's nothing wrong with building dicts or other lookup tables outside a function in order to avoid re-creating them every time the function is called. However, please consider writing complete, pronounceable names for variables. This looks like Fortran! -- http://mail.python.org/mailman/listinfo/python-list
Re: What is built-in method sub
trailingPattern = '(\S*)\ +?\n' line = re.sub(trailingPattern, '\\1\n', line) What happens with this? trailingPattern = '\s+$' line = re.sub(trailingPattern, '', line) I'm guessing that $ terminates \s+'s greediness without snarfing the underlying \n. Then I'm guessing that the lack of a \1 replacer will help the sub work faster with less internal string shuffling. line = line.rstrip()? is probably faster still, but there might be a technical reason to avoid it. But these uncertainties are why I write unit tests, including tests for the edge cases. (What if it's a \r\n? What if the \n is missing? etc.) That way I don't need to memorize re's exact behavior, and if I find a reason to swap in a .rstrip(), I can pass all the tests and make sure the substitution works the same. -- Phlip http://c2.com/cgi/wiki?ZeekLand -- http://mail.python.org/mailman/listinfo/python-list
Re: Author of a Python Success Story Needs a Job!
Andrew Jonathan Fine wrote: I was laid off by Honeywell several months after I had made my presentation in the 2005 Python Conference. Since then I have been unable to find work either as a software engineer or in any other capacity, even at service jobs. I've sent resumes and have been consistently ignored. 6 years ago the silver bullet there was Java. Today, it is Rails. I happen to suspect Django has a superior architecture, but it's still RoR that's flying off the shelves these days. (And, under MERB's tutelage, they will soon surpass Django for modularity!) -- Phlip http://zeekland.zeroplayer.com/Uncle_Wiggilys_Travels/1 -- http://mail.python.org/mailman/listinfo/python-list
Re: Writing a string.ishex function
MRAB wrote:
BTW, ishex('') should return False.
So should int('')!
--
http://mail.python.org/mailman/listinfo/python-list
Re: unittest help needed!
Oltmans wrote: def test_first(self): print 'first test' process(123) All test cases use the pattern "Assemble Activate Assert". You are assembling a 123, and activating process(), but where is your assert? If it is inside process() (if process is a test-side method), then that should be called assert_process(). As you can see, every test method is almost same. Only difference is that every test method is calling process() with a different value. Also, I've around 50 test methods coded that way. We wonder if your pattern is truly exploiting the full power of testing. If you have ~15 different features, you should have ~50 tests (for a spread of low, middle, and high input values, to stress the targeted production code). But this implies your 15 different features should have as many different interfaces - not the same interface over and over again. That suggests coupled features. Anyway, the short-term answer is to temporarily abandon "AAA", and roll up your input values into a little table: for x in [123, 327, 328, ... ]: process(x) (Also, you don't need the print - tests should run silent and unattended, unless they fail.) This refactor is the standard answer to the question "I have an unrolled loop". You roll it back up into a table iteration. However, you lose the test case features, such as restartability and test isolation, that AAA give you. Long term, you should use a literate test runner, such as (>cough<) my Morelia project: http://c2.com/cgi/wiki?MoreliaViridis Down at the bottom, that shows how to create a table of inputs and outputs, and Morelia does the unrolling for you. -- Phlip http://zeekland.zeroplayer.com/Uncle_Wiggilys_Travels/1 -- http://mail.python.org/mailman/listinfo/python-list
Re: Author of a Python Success Story Needs a Job!
Aahz wrote: In article <6a12ed15-e7f9-43ab-9b90-984525808...@o28g2000yqh.googlegroups.com>, Novocastrian_Nomad wrote: Why is it so many, so called high tech companies, insist on the 19th century practice of demanding an employee's physical presence in a specific geographic location. Because it works better? My current job is mostly done at the office, and I think it leads to better morale in many ways. I'm not sure about productivity, though. Ironically, I have heard that if your bossoids are enlightened enough to require pair programming for most development, and if you install a full telecommuting rig of remote eyeballs, Skype with audio, and a remote desktop solution such as VNC, you can remotely pair very productively. (He posted from work, soloing! ;) -- Phlip -- http://mail.python.org/mailman/listinfo/python-list
Re: Changing var names
Adam Tauno Williams wrote: This process is called 'refactoring' [a good term to Google], and every decent IDE provides some support [if it doesn't, it isn't a "decent" IDE] Way more important than IDE support is developers writing wall-to-wall unit tests as they write their features, _before_ refactoring them. [If they don't, they aren't "decent" developers, either!;] Don't even call it "refactoring" without test support! Sadly IDEs for Java and .NET are still pretty far ahead of what is available for Python. That is bizarre and inconceivable, given Python's typing is almost as static as thoses's. (Yes yes yes Python does not force you to declare _every_ type. Just _many_ of them...) http://www.oreillynet.com/onlamp/blog/2008/05/dynamic_languages_vs_editors.html >> Also, if anyone has any other suggestions they've been holding back, >> or had mentioned earlier, on how to improve my design Write scads of unit tests! -- Phlip -- http://mail.python.org/mailman/listinfo/python-list
Re: Changing var names
Victor Subervi wrote: > Should I re-write it in classes before testing units? Right now it's > very monolithic. The "Unit" in unit tests is a misnomer. It refers to an old QA concept, for high-end projects, that the failure of any test should implicate only one unit. We only need "developer tests". They help, when we change the code, to avoid excessive debugging. And to test a given method you must be able to access it, so tests force your code to be decoupled. But a test may call as many functions as it needs, regardless what "unit" they live in. If you don't have tests yet, then sometimes a rewrite is indicated (and sometimes it's very easy and will produce _very_ clear code!). But in most cases like yours the best advice is to write your next feature using "test driven development". Write the test first, get it to fail, then change the code as little as possible to get it to pass. Repeat until done, occasionally refactoring. If old code now works, just leave it alone. Until it needs a new feature, and then wham! it has tests. -- Phlip http://zeekland.zeroplayer.com/Uncle_Wiggilys_Travels/1 -- http://mail.python.org/mailman/listinfo/python-list
Re: BeautifulSoup
John Bokma wrote: John Nagle writes: It's just somebody pirating movies. Ineptly. Ignore. Wow, what a childish reply. You should've followed your own advice and ignored the OP instead of replying with a top post + full quote (!). Mr Manners reminds the Gentle Poster(s) that... A> as Google vs China shows, all programmers should resist hacking, no matter how inept it may be, by any means necessary B> John should not have attempted to leave a dead trail in the archives. Searches for BeautifulSoup should always return answered questions. -- Phlip -- http://mail.python.org/mailman/listinfo/python-list
Re: BeautifulSoup
John Nagle wrote: It's just somebody pirating movies. Ineptly. Ignore. Anyone who leaves their movies hanging out in tags, without a daily download limit or a daily hashtag, deserves to be taught a lesson! -- Phlip -- http://mail.python.org/mailman/listinfo/python-list
Re: Is python not good enough?
On Jan 12, 7:09 am, ikuta liu wrote: > Go language try to merge low level, hight level and browser language. Go uses := for assignment. This means, to appease the self-righteous indignation of the math professor who would claim = should mean "equality"... ...you gotta type a shift and 2 characters for a very common operator. Pass! -- Phlip -- http://mail.python.org/mailman/listinfo/python-list
Re: Is python not good enough?
On Jan 18, 5:59 am, Anh Hai Trinh wrote: > > Go uses := for assignment. > > Except that it doesn't. := is a declaration. Ah, and that's why Go is easy for cheap parsers to rip. Tx all! I was formerly too mortified to proceed - now I'm back in the Go camp. They fixed the hideous redundancy of Java without the ill-defined scope issues of Python & Ruby, and without the tacky little 'var' of JavaScript! -- http://mail.python.org/mailman/listinfo/python-list
Re: Is HTML report of tests run using PyUnit (unittest) possible?
On Jan 19, 3:16 am, fossist wrote: > I am using PyUnit (unittest module) for loading test cases from our > modules and executing them. Is it possible to export the test results > as HTML report? Currently the results appear as text on standard > output while the tests execute. But is there something out of the box > available in PyUnit to make this possible? django-test-extensions can do this, but I'm unaware how well it works without Django. (And I _could_ complain that it comes with one or two irritations _with_ Django;) I would download it and read its source to see how the --xml option works. (Then you'd use a XSL filter to rip the XML into HTML...) -- Phlip http://c2.com/cgi/wiki?ZeekLand -- http://mail.python.org/mailman/listinfo/python-list
Re: Python IDE for MacOS-X
On Jan 18, 11:09 pm, Jean Guillaume Pyraksos wrote: > What's the best one to use with beginners ? > Something with integrated syntax editor, browser of doc... > Thanks, Before this message goes stale, there's TextMate (which I have too much experience with to consider redeemable in any way)... ...and there's Komodo Edit. The problems I have with that are... - the code browsing breaks when the wind blows, and you must Find in Files (my library, Django, is symlinked below my project, so FiF can see it) - the editor refuses to let me run a script - such as a test script - each time I hit F5. For whatever reason - poor keyboard remapping, or lack of a plug-in for Django - I must use Ctrl+R to run a batch file, just to test. Testing should be ONE (1) keystroke. - FiF sees my .git folder, and everything in it. WTF?? - after searching or anything, I must click the editor with the mouse to resume editing. should move the focus out of the frame to the editor, and of course any activity that takes you out of the editor should dump you back into it by default Other than that, it has all the standard edito My problem with Mac in general is the keystrokes are always so broken they force me to switch to a mouse. Nobody seems to usability test these things and see how long you can type & manipulate windows without -- http://mail.python.org/mailman/listinfo/python-list
Re: counting lines of code
On Jan 20, 11:20 pm, Michele Simionato wrote: > pylint does too many things, I want something fast that just counts > the lines and can be run on thousands of files at once. > cloc seems fine, I have just tried on 2,000 files and it gives me a > report in just a few seconds. In my experience with Python codebases that big... ...how many of those lines are duplicated, and might merge together into a better design? The LOC would go down, too. -- Phlip -- http://mail.python.org/mailman/listinfo/python-list
Re: counting lines of code
Aahz wrote: In article <[email protected]>, Phlip wrote: On Jan 20, 11:20=A0pm, Michele Simionato wrote: pylint does too many things, I want something fast that just counts the lines and can be run on thousands of files at once. cloc seems fine, I have just tried on 2,000 files and it gives me a report in just a few seconds. In my experience with Python codebases that big... ...how many of those lines are duplicated, and might merge together into a better design? Um... do you have any clue who you followed up to? If you don't, Google is your friend. Oh, sorry, did I have the wrong opinion? -- http://mail.python.org/mailman/listinfo/python-list
Re: counting lines of code
On Jan 21, 9:00 pm, Michele Simionato wrote: > Just for fun I have run cloc on our trunk: > > SUM: 8743 272238 215871 1470139 x 1.84 = > 2708354.95 Nice! My favorite version of a cloc system can distinguish test from production code. That's why I always use executable cloc to measure the ratio of test to production code (where 1.2:1 is almost comfortable an 2:1 is sacred). Just so long as nobody confuses "more lines of code!" with progress... -- Phlip -- http://mail.python.org/mailman/listinfo/python-list
where's self.assertMatch (for Django)?
Hypo Nt: Been a while, now I'm back, and the first helpless question is... When I google (including codesearch) for assertMatch, I get a mishmash of opinions. Am I missing the One True assertMatch(), or isn't there one and I gotta write it? or copy and use one of the pretenders? Distractingly-yrs, -- Phlip http://zeekland.zeroplayer.com/Pigleg_Too/1 -- http://mail.python.org/mailman/listinfo/python-list
Re: where's self.assertMatch (for Django)?
> When I google (including codesearch) for assertMatch, I get a mishmash of > opinions. Am I missing the One True assertMatch(), or isn't there one and I > gotta write it? or copy and use one of the pretenders? Ookay, try this: def assertMatch(self, pattern, slug): r = re.compile(pattern) self.assertNotEqual(None, r.search(smart_str(slug))) To do: Pass thru an optional diagnostic message. Anyone know why this is not in PyUnit? > -- > Phlip > http://zeekland.zeroplayer.com/Pigleg_Too/1 -- http://mail.python.org/mailman/listinfo/python-list
how to create a pip package
Py hont: I have a single file that I need my crew to pip install. When I Google for "how to create a pip package" I don't hit anything. Of course that info is out there; I can't seem to pick up the trail of breadcrumbs to it. While I'm looking, could someone push the link in here? Purely for posterity? Thanks! -- Phlip http://c2.com/cgi/wiki?ZeekLand -- http://mail.python.org/mailman/listinfo/python-list
Re: how to create a pip package
On Nov 10, 1:54 am, Wolodja Wentland wrote: > http://docs.python.org/library/distutils.html#module-distutils > http://packages.python.org/distribute/ ktx... now some utterly retarded questions to prevent false starts. the distutils page starts with "from distutils.core import setup". but a sample project on github, presumably a pippable project, starts with: from setuptools import setup, find_packages (and it also has ez_setup()) I don't foresee my project growing larger than one* file any time soon. 'pip freeze' prob'ly won't write a setup.py. What is the absolute simplest setup.py to stick my project on the PYTHONPATH, and be done with it? [*but rest assured it has a developer test suite and a customer test script!] -- Phlip http://c2.com/cgi/wiki?ZeekLand -- http://mail.python.org/mailman/listinfo/python-list
Re: how to create a pip package
> > from setuptools import setup, find_packages > > It will be enough to use the method outlined in the distutils > documentation. Setuptools is a third-party library that used to be the > de-facto standard for Python packaging. I don't want to go into detail > why setuptools might not be the best choice for a project... Good - thanks, all! Those were the exact details I sought to avoid... -- http://mail.python.org/mailman/listinfo/python-list
Re: how to create a pip package
except... will pip pull from a simple GitHub repo? or do I need to package something up and put it in a pythonic repository somewhere? -- http://mail.python.org/mailman/listinfo/python-list
Re: how to create a pip package
On Nov 10, 3:11 pm, Wolodja Wentland wrote: > The pip requirement file would contain the following line: > > -e git+git://example.com/repo.git#egg=rep I thought pip didn't do eggs. did I read a stale blog? > I hope this answers your questions :-D we are so close! Pages like this... http://blog.ianbicking.org/2008/12/16/using-pip-requirements/ ...are answering the question "what if I have ten billion requirements?" I have one, Python. What's the simplest pip requirement file? I will post here if I figure it out first. -- http://mail.python.org/mailman/listinfo/python-list
Re: how to create a pip package
On Nov 10, 3:11 pm, Wolodja Wentland wrote: > The pip requirement file would contain the following line: > > -e git+git://example.com/repo.git#egg=rep > > I hope this answers your questions :-D Let me ask it like this. What happens when a user types..? sudo pip install repo Is github one of the default sites pip scans? If so, will it rip a requirements file in the root of repo.git? If so, what file name should that have? All the pages I'm reading start at the complex end of the requirements file concept. They don't seem to mention simple things like the name of the file, or how to lead pip to the file. -- http://mail.python.org/mailman/listinfo/python-list
Re: how to create a pip package
> > -e git+git://example.com/repo.git#egg=rep Okay. -e is an argument to pip install. If anyone said that, I overlooked it. So, yes I can rip from github, just with a longer command line, for now. Tx! -- http://mail.python.org/mailman/listinfo/python-list
How can pip install a GitHub code drop?
Not Hyp: Suppose I have a Python library, complete with a respectable setup.py. How can I point pip at the repo to install the library? if I use this... sudo pip -e git+git://github.com/Phlip/Kozmiq.git ...I get an editable drop in a ~/src/ folder. -- Phlip http://c2.com/cgi/wiki?ZeekLand -- http://mail.python.org/mailman/listinfo/python-list
combinatorics via __future__ generators
Python: I have a quaint combinatorics problem. Before I solve it, or find a solution among "generators", I thought y'all might like to show off any solutions. Given an array like this... [0, 4, 3] Produce an array like this: [ [0, 0, 0], [0, 1, 0], [0, 2, 0], [0, 3, 0], [0, 1, 1], [0, 2, 1], [0, 3, 1], [0, 1, 2], [0, 2, 2], [0, 3, 2], ] The first array is the counts of options in 4 slots, and the second is all combinations of indexes of each option, such that every option associates once with every other option. The leading 0 simply represents a slot with no options; the algorithm must preserve those. This should be child's play for the generator package, right? -- Phlip http://zeekland.zeroplayer.com/ -- http://mail.python.org/mailman/listinfo/python-list
Re: combinatorics via __future__ generators
On Nov 18, 4:58 pm, Phlip wrote: > Python: > > I have a quaint combinatorics problem. Before I solve it, or find a > solution among "generators", I thought y'all might like to show off > any solutions. > > Given an array like this... > > [0, 4, 3] > > Produce an array like this: > > [ > [0, 0, 0], > [0, 1, 0], > [0, 2, 0], > [0, 3, 0], [0, 0, 1], > [0, 1, 1], > [0, 2, 1], > [0, 3, 1], [0, 0, 2], > [0, 1, 2], > [0, 2, 2], > [0, 3, 2], > ] I forgot those combinations! > > The first array is the counts of options in 4 slots, and the second is > all combinations of indexes of each option, such that every option > associates once with every other option. The leading 0 simply > represents a slot with no options; the algorithm must preserve those. > > This should be child's play for the generator package, right? > > -- > Phlip > http://zeekland.zeroplayer.com/ -- http://mail.python.org/mailman/listinfo/python-list
Re: Dreaming of new generation IDE
On Feb 3, 3:10 am, Vladimir Ignatov wrote: > Finally I develop a feeling that strong instrumentation / tools can > bring us the best of two worlds. That I am dreaming on is an absolute > new type/class of IDE suitable for Python and potentially for other > dynamic-type languages. Instead of current text-oriented IDEs, it > should be a database-centric and resemble current CAD systems instead > of being just "fancy text editor". Source text should be an output > product of that CAD and not a "source material" itself. That's fine so long as I can also treat the source as source, at need. You may have just reinvented Smalltalk's Squeak editor (reputedly the testbed for all of modern GUIs...). Current editors suck because they can't see into the code and browse it - unless it's so statically typed it's painful. That's why I wrote this: http://www.oreillynet.com/onlamp/blog/2008/05/dynamic_languages_vs_editors.html -- http://mail.python.org/mailman/listinfo/python-list
Re: Dreaming of new generation IDE
On Feb 3, 10:57 am, Adam Tauno Williams
wrote:
> > Current editors suck because they can't see into the code and browse
> > it - unless it's so statically typed it's painful.
>
> ? I edit Python in MonoDevelop 2.2; and I can browse my file,
> classes, etc... So I don't know what you mean by "can't see into the
> code". It works pretty well.
>
> Of course it can't tell that I've set x = {an integer}, as that only
> happens at runtime.
>
> > That's why I wrote this:
> > http://www.oreillynet.com/onlamp/blog/2008/05/dynamic_languages_vs_editors.html
You just said that your code browsing "works pretty well, except when
it doesn't".
Hence my blog entry. If your editor analyzed your code at runtime,
instead of just static analysis, then it could see that x = an
integer, or an object, no matter how dynamic your language.
--
Phlip
http://zeekland.zeroplayer.com/Uncle_Wiggilys_Travels/1
--
http://mail.python.org/mailman/listinfo/python-list
Re: The best library to create charting application
mk wrote: The application will display (elaborate) financial charts. Pygame? Smth else? Back in the day it was Python BLT. Are you on the Web or the Desktop? -- Phlip http://www.oreillynet.com/onlamp/blog/2008/05/dynamic_languages_vs_editors.html -- http://mail.python.org/mailman/listinfo/python-list
Re: Dreaming of new generation IDE
John Bokma wrote:
> my $x = ( 5, "hello", sub {}, [], {} )[ int rand 5 ];
>
> what's $x? The answer is: it depends.
That's why my blog post advocated (as usual for me) developer tests.
Then you either mock the rand, like all developers should, or you get
what you pay for, and Principle of Least Surprise still applies...
Over the past decade, teams discovered that developer tests more than
made up for the lack of rigor in dynamic languages. A dynamic language
with tests can be more productive than a static language, even with
its runtime type checks AND with its tests.
However, our editors must catch up to us. When I test, I am statically
declaring a set of types, even if the language would prefer to
dynamically fling them hither and yon. We should leverage that.
--
Phlip
--
http://mail.python.org/mailman/listinfo/python-list
equivalent of Ruby's Pathname?
Pythonistas: Yes, calling os.path.walk() and os.path.join() all the time on raw strings is fun, but I seem to recall from my Ruby days a class called Pathname, which presented an object that behaved like a string at need, and like a filesystem path at need. path + 'folder' would call .join() and insert the / correctly, for example. What's the best equivalent in Python-land? -- Phlip -- http://mail.python.org/mailman/listinfo/python-list
reconstruct the source of a lambda from its func_code, func_name, etc
Thy Pon: Has anyone figured out how to reflect a passed function, such as a lambda, all the way back to its source? I am aware than func_code knows the file name and line number; I would rather not use them to read the file because the lambda might not start in the first column. I will go with this option until someone suggests a better fix! -- Phlip http://penbird.tumblr.com/ -- http://mail.python.org/mailman/listinfo/python-list
Re: intolerant HTML parser
Stefan Behnel wrote: > I don't read it that way. There's a huge difference between > > - generating HTML manually and validating (some of) it in a unit test > > and > > - generating HTML using a tool that guarantees correct HTML output > > the advantage of the second approach being that others have already done > all the debugging for you. Anyone TDDing around HTML or XML should use or fork my assert_xml() (from django-test-extensions). The current version trivially detects a leading tag and uses etree.HTML(xml); else it goes with the stricter etree.XML(xml). The former will not complain about the provided sample HTML. Sadly, the industry has such a legacy of HTML written in Notepad that well-formed (X)HTML will never be well-formed XML. My own action item here is to apply Stefan's parser_options suggestion to make the etree.HTML() stricter. However, a generator is free to produce arbitrarily restricted XML that avoids the problems with XHTML. It could, for example, push any Javascript that even dreams of using & instead of & out into .js files. So an assert_xml() hot-wired to process only XML - with the true HTML doctype - is still useful to TDD generated code, because its XPath reference will detect that you get the nodes you expect. -- Phlip http://c2.com/cgi/wiki?ZeekLand -- http://mail.python.org/mailman/listinfo/python-list
Re: intolerant HTML parser
and the tweak is:
parser = etree.HTMLParser(recover=False)
return etree.HTML(xml, parser)
That reduces tolerance. The entire assert_xml() is (apologies for
wrapping lines!):
def _xml_to_tree(self, xml):
from lxml import etree
self._xml = xml
try:
if ' 0, xpath + ' not found in ' +
self._xml)
node = nodes[0]
if kw.get('verbose', False): self.reveal_xml(node) # "here
have ye been? What have ye seen?"--Morgoth
return node
def reveal_xml(self, node):
'Spews an XML node as source, for diagnosis'
from lxml import etree
print etree.tostring(node, pretty_print=True) # CONSIDER
does pretty_print work? why not?
def deny_xml(self, xml, xpath):
'Check that a given extent of XML or HTML does not contain a
given XPath'
tree = self._xml_to_tree(xml)
nodes = tree.xpath(xpath)
self.assertEqual(0, len(nodes), xpath + ' should not appear in
' + self._xml)
--
http://mail.python.org/mailman/listinfo/python-list
Re: equivalent of Ruby's Pathname?
On Feb 8, 2:36 pm, [email protected] (Aahz) wrote: > >> There was also a PEP with another possible implementation: > >>http://www.python.org/dev/peps/pep-0355/ > > >Why did Path() get rejected? Is it the idea itself, or just the > >approach that was used? What are the complaints? > > You should search for the discussiona around it. I, OTOH, am burning rubber with Python 2.6.1, so leading edge concerns are not mine - yet! I went with this version, generously ripped out & plopped into our project: # URL: http://www.jorendorff.com/articles/python/path # Author: Jason Orendorff (and others - see the url!) # Date:7 Mar 2004 class path(_base): """ Represents a filesystem path. """ Gods bless http://www.google.com/codesearch, huh?! -- Phlip http://c2.com/cgi/wiki?ZeekLand -- http://mail.python.org/mailman/listinfo/python-list
Re: equivalent of Ruby's Pathname?
Carl Banks wrote:
> I don't know if it was the reason it was rejected, but a seriously
> divisive question is whether the path should be a subset of string.
OMG that's nothing but the OO "circle vs ellipse" non-question. Glad
to see the Committee derailed a perfectly good library over such
sophistry.
> Under ordinary circumstances it would be a poor choice for inheritance
> (only a few string methods would be useful fot a pathname), but some
> people were fiercely adamant that paths should be passable to open()
> as-in (without having to explicity convert to string).
That's just silly. To be object-based, you should say path.open('r').
fopen() and its ilk are too 1960s...
My 5th Grade science teacher, one Eunice Feight, once expressed
chagrin for submitting a proposal to Readers' Digest, and getting it
accepted. She sold them the following sloka:
Don't be clever don't be witty
Or you'll wind up BEING the Committee!
--
Phlip
http://penbird.tumblr.com/
--
http://mail.python.org/mailman/listinfo/python-list
Re: equivalent of Ruby's Pathname?
Gregory Ewing wrote: > It wouldn't just be open() that people would want modified -- > it would be every other function that takes a pathname as > well. Then refer to the same argument against implicit type conversions in C+ +. A ::std::string must call .c_str() to turn into a lowly char*, before passing into a C function. Advocating for 8 characters of convenience opens the risk of silent bugs at refactor time. > I seem to recall another point of contention was whether > path objects should have methods for accessing the file > system (opening files, renaming them, etc.) or whether it > should confine itself to representing and manipulating > pathnames. In that case, the package I picked seems to have "erred" on the side of programmer convenience. Because the basic file operations (exist, stat, move/rename, copy, open, chmod, unlink) come as a complete and whole kit, a class should simply present that kit, insulating against filesystem differences. > In any case, introducing any kind of path object at this > late stage of the language's development would result in > More Than One Way to represent pathnames, with neither of > them being the obvious choice. Ah, now we get down to the root of the problem. Because Python is so stuck on the "one best way to do it" mentality, language bigotry prevented the Committee from picking from among several equally valid but non-best options. And after 20 years of growth, Python still has no Pathname class. What a mature community! C-: -- Phlip http://c2.com/cgi/wiki?MoreliaViridis -- http://mail.python.org/mailman/listinfo/python-list
