Re: Line-by-line processing when stdin is not a tty

2010-08-11 Thread Cameron Simpson
On 11Aug2010 10:32, Tim Harig wrote: | On 2010-08-11, Wolfgang Rohdewald wrote: | > On Mittwoch 11 August 2010, Cameron Simpson wrote: | >> Usually you either | >> need an option on the upstream program to tell it to line | >> buffer explicitly | > | > once cat had

Re: Line-by-line processing when stdin is not a tty

2010-08-11 Thread Cameron Simpson
ine buffering then the whole situation is racey and unreliable. You can see that on reflection this isn't easy to resolve cleanly from _outside_ the writing program. To do it from inside requires all programs to sprout an option like GNU cat's -u option. Cheers, -- Cameron Simpson D

Re: How to capture all the environment variables from shell?

2010-08-11 Thread Cameron Simpson
On 12Aug2010 01:28, Nobody wrote: | On Wed, 11 Aug 2010 13:08:59 +1000, Cameron Simpson wrote: | > The reason .bashrc gets overused for envars, aside from ignorance and | > propagated bad habits, is that in a GUI desktop the setup sequence is | > often a bit backwards. A conventional

Re: How do I get number of files in a particular directory.

2010-08-13 Thread Cameron Simpson
returned to you? The len() built in function suggests itself... -- Cameron Simpson DoD#743 http://www.cskk.ezoshosting.com/cs/ -- http://mail.python.org/mailman/listinfo/python-list

Re: Simple Python Sandbox

2010-08-14 Thread Cameron Simpson
er they like in python because they won't be presented with the inner parts of the privileged stuff. This is all rather vague because I don't know exactly what your untrusted users need to be able to do, nor how. Cheers, -- Cameron Simpson DoD#743 http://www.cskk.ezoshosting.com/cs/ C

Re: String substitution VS proper mysql escaping

2010-08-17 Thread Cameron Simpson
ing. Otherwise, because a string _is_ a sequence the "%" might want to treat the string "foo" as the sequence: ("f", "o", "o") Run these three loops to see the difference: for s in "foo": print s for s in ("foo"):

Re: String substitution VS proper mysql escaping

2010-08-18 Thread Cameron Simpson
On 18Aug2010 12:07, Nik Gr wrote: | Στις 18/8/2010 7:31 πμ, ο/η Cameron Simpson έγραψε: | >On 17Aug2010 20:15, Νίκος wrote: | >| === | >| cursor.execute( ''' SELECT host, hits, date FROM visitors WHERE page = | >| '%s

Re: String substitution VS proper mysql escaping

2010-08-19 Thread Cameron Simpson
ython "%" format operator at all. This is the database API's .execute() method. If it expects its second argument to be a sequence of parameters (which is does) then you need to supply a sequence of parameters. It is that simple! In you usage above you're supplying "page

Re: #! to two different pythons?

2009-06-06 Thread Cameron Simpson
and is largely symlinks to preferred versions of apps, apps installed out of the main paths, and host-specific wrapper scripts. Cheers, -- Cameron Simpson DoD#743 http://www.cskk.ezoshosting.com/cs/ Soon, Grasshopper, all will understand. And dispair. The government that defines what is good for

Pythonic way to overwrite a file

2009-06-17 Thread Cameron Pulsford
Hey all, hopefully a simple question. I'm writing a simple python tool that opens a file, and does something like for line in file.readlines(): temp.write(line.doStuff()) However, I want to provide the option do this "in place", as in have the destination file be the same as the source file.

Re: Pythonic way to overwrite a file

2009-06-17 Thread Cameron Pulsford
c...@sequans.com> wrote: > Cameron Pulsford wrote: > >> Hey all, hopefully a simple question. >> >> I'm writing a simple python tool that opens a file, and does something >> like >> >> for line in file.readlines(): >>temp.write(line.doStuf

Reading and setting file permissions programmatically

2009-06-17 Thread Cameron Pulsford
Sorry to flood the list but my google fu isn't up to par today I guess. Basically, is it possible to read the permissions on one file and then set the permissions of another file to the ones we just read? os.dup2 seemed like it would work but I might not be using it correctly. I know there is os.c

Help with dictionaries and multidimensial lists

2009-06-23 Thread Cameron Pulsford
Hey all, I have a dictionary that looks like this (small example version) {(1, 2): 0} named a so I can do a[1,2] which returns 0. What I also have is a list of coordinates into a 2 dimensional array that might look like this b = [[1,2]]. Is there anyway I can call a[b[0]] and have it return 0? --

Re: Help with dictionaries and multidimensial lists

2009-06-23 Thread Cameron Pulsford
Thanks! On Tue, Jun 23, 2009 at 11:29 AM, Jaime Fernandez del Rio < jaime.f...@gmail.com> wrote: > On Tue, Jun 23, 2009 at 4:45 PM, Cameron > Pulsford wrote: > > Hey all, I have a dictionary that looks like this (small example version) > > {(1, 2): 0} named a > >

Re: handling https sites

2009-06-30 Thread Cameron Simpson
://bugs.python.org/issue1424152 There's a patch under review. -- Cameron Simpson DoD#743 http://www.cskk.ezoshosting.com/cs/ -- http://mail.python.org/mailman/listinfo/python-list

Problem with list of dicts and copying

2009-07-08 Thread Cameron Pulsford
Hello all, I'm redoing a sudoku solver of mine and I ran into an issue with lists of dicts. Bear with me for a second before I get to the actual problem... I'm representing the board as a dictionary, where the keys are (x, y) positions, and the values are candidates. So my program goes along pickin

Question about generators

2009-07-12 Thread Cameron Pulsford
Hey everyone, I have this small piece of code that simply finds the factors of a number. import sys def factor(n): primes = (6*i+j for i in xrange(1, n) for j in [1, 5] if (i+j)%5 ! = 0) factors = [] for i in [2, 3, 5]: while n % i == 0: n /= i f

Re: Question about generators

2009-07-12 Thread Cameron Pulsford
ng up! On Jul 12, 2009, at 8:15 PM, Terry Reedy wrote: Cameron Pulsford wrote: When you start a new thread, you should start a new thread and not piggyback on an existing thread. -- http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list

Re: Question about generators

2009-07-12 Thread Cameron Pulsford
I was initially looking at it there are some interesting patterns I might be able to extend into a generator that would yield only correct sets of numbers for the 6x + n pattern. On Jul 12, 2009, at 10:26 PM, John Machin wrote: On Jul 13, 11:24 am, Cameron Pulsford wrote: As far as the p

Re: [Diversity] Language note

2009-08-23 Thread Cameron Laird
In article , Rami Chowdhury wrote: > >> Most indian languages have a different >> grammer (compared to English). So i'm curious to see how that would be >> implemented in a parser > >+1 -- I'd be interested in seeing this too, although we have drifted >OT here and perhaps this conversation woul

Re: Sqlite format string

2009-08-29 Thread Cameron Simpson
This: ( user ) is not a tuple containing the element user. It's just user. This: ( user, ) is what you want. -- Cameron Simpson DoD#743 http://www.cskk.ezoshosting.com/cs/ [Alain] had been looking at his dashboard, and had not seen me, so I ran into him. - Jean Alesi on his qualifyin

Re: Non-deprecated equivalent of rfc822.AddressList

2009-09-21 Thread Cameron Simpson
from email.utils import parseaddr, getaddresses, formataddr See the pydoc for email.utils; it's very easy to use. Cheers, -- Cameron Simpson DoD#743 http://www.cskk.ezoshosting.com/cs/ Reason #173 to fear technology: o o o o o o ^|\ ^|^

Re: Python-URL! - weekly Python news and links (Sep 17)

2009-09-24 Thread Cameron Laird
In article , Gabriel Genellina wrote (but I edited): . . . >More ways to define an empty function that you ever imagined: >http://groups.google.com/group/comp.lang.python/t/c9f494b6745c7d74/

Re: Optimising literals away

2010-08-31 Thread Cameron Simpson
ver stored anywhere (bound to a name, for example) then it | could be created once. When the expression is evaluated there could be | a check so see whether 'set' is bound to the built-in class, and, if it | is, then just use the pre-created set. Wouldn't you need to repeat that ch

Re: Optimising literals away

2010-08-31 Thread Cameron Simpson
On 31Aug2010 23:38, MRAB wrote: | On 31/08/2010 23:11, Cameron Simpson wrote: | >On 31Aug2010 22:53, MRAB wrote: | >| There's still the possibility of some optimisation. If the resulting | >| set is never stored anywhere (bound to a name, for example) then it | >| could be creat

Re: How Python works: What do you know about support for negative indices?

2010-09-11 Thread Cameron Simpson
d, and I skipped most of the | > message because of that. | | You might want to switch to a client where you do not have this problem. It was fine for me too, using mutt (fixed width text interface, 80 column terminal). -- Cameron Simpson DoD#743 http://www.cskk.ezoshosting.com/cs/ A monkey

Re: How do you preserve time values with date.datefromtimestamp()

2010-09-15 Thread Cameron Simpson
a lot better off not considering it as a storage value or as a value to print, unless you actually need to work in the domains where it is used. Cheers, -- Cameron Simpson DoD#743 http://www.cskk.ezoshosting.com/cs/ Tiggers don't like honey. - A.A.Milne, The House at Pooh Corner -- http://mail.python.org/mailman/listinfo/python-list

Re: Too many threads

2010-09-16 Thread Cameron Simpson
), removing the possibility of mismanagement of the output if print() is not thread safe. Cheers, -- Cameron Simpson DoD#743 http://www.cskk.ezoshosting.com/cs/ Rules of Optimization: Rule 1: Don't do it. Rule 2 (for experts only): Don't do it yet. - M.A. Jackson -- http://mail.python.org/mailman/listinfo/python-list

Re: Too many threads

2010-09-16 Thread Cameron Simpson
On 16Sep2010 22:14, Ned Deily wrote: | In article <20100917043826.ga21...@cskk.homeip.net>, | Cameron Simpson wrote: | | > On 16Sep2010 09:55, mark.pellet...@asrcms.com | > wrote: | > | For some reason, the tasks I put into my thread pool occasionally get | > |

Re: The trouble with "dynamic attributes".

2010-09-17 Thread Cameron Simpson
uld also fail in this instance -- how is | this worked-around? I'd be inclined to go for ('foo', 'bar'), though that makes all the single occurence nodes into sequences too, a bit cumbersome:-( -- Cameron Simpson DoD#743 http://www.cskk.ezoshosting.com/cs/ alt.s

Re: resource module returns just zeros

2010-10-04 Thread Cameron Simpson
ll has GNU ps). Also look in /proc - the info may be available there - I expect that's where a Linux ps gets a lot of info. Cheers, -- Cameron Simpson DoD#743 http://www.cskk.ezoshosting.com/cs/ I do not like this word 'bomb'. It is not a bomb. It is a device which is explodi

Re: Boolean value of generators

2010-10-14 Thread Cameron Simpson
generator iterate opening foo closing foo done You can see there that the generator _body_ doesn't even run until you start the iteration. Does this clarify things for you? Cheers, -- Cameron Simpson DoD#743 http://www.cskk.ezoshosting.com/cs/ Winter is gods' way of telling us to polish. - Peter Harper -- http://mail.python.org/mailman/listinfo/python-list

Re: Boolean value of generators

2010-10-14 Thread Cameron Simpson
out an explicit wrapper to | request it: [... damaging counter example ...] +1 to this. Speaking for myself, I would _not_ want a generator to commence execution unless I overtly iterate over it. I suppose we can cue the "hasattr() runs getattr(), ouch!" discussion here:-) Cheers, --

Re: extract method with generators

2010-10-14 Thread Cameron Simpson
s the decorated generator. Cheers, -- Cameron Simpson DoD#743 http://www.cskk.ezoshosting.com/cs/ What I want is Facts. Teach these boys and girls nothing but Facts. Facts alone are wanted in life. Plant nothing else, and root out everything else. - Charles DickensJohn Huffam 18

Re: Deferring a function call

2010-10-18 Thread Cameron Simpson
heers, -- Cameron Simpson DoD#743 http://www.cskk.ezoshosting.com/cs/ A crash reduces your expensive computer to a simple stone. - Haiku Error Messages http://www.salonmagazine.com/21st/chal/1998/02/10chal2.html -- http://mail.python.org/mailman/listinfo/python-list

Re: yield all entries of an iterable

2010-10-24 Thread Cameron Simpson
af nodes. The point is that you're calling leaves() on the subnode and yiled them directly to the outside. The caller may not even know there are "subnodes". Cheers, -- Cameron Simpson DoD#743 http://www.cskk.ezoshosting.com/cs/ The Borg assimilated my race and all I got was this

Re: yield all entries of an iterable

2010-10-24 Thread Cameron Simpson
| describe is `os.walk`. Indeed. I'm surprised it didn't occur to me. Cheers, -- Cameron Simpson DoD#743 http://www.cskk.ezoshosting.com/cs/ The only thing necessary for the triumph of evil is for good men to do nothing. - Edmund Burke (1729-1797) -- http://mail.python.org/mailma

Re: What people are using to access this mailing list

2010-11-03 Thread Cameron Simpson
| of following this and other lists. I use mutt to read my python folder. I use getmail to collect email via POP and deliver via procmail, which files this list (and python-ideas etc) into a "python" folder, out of my main inbox. -- Cameron Simpson DoD#743 http://www.cskk.ezoshosting

Re: Python documentation too difficult for beginners

2010-11-03 Thread Cameron Simpson
d it leads to "drier" documentation. It also works well for Java because it is strongly typed - a great deal of the structure in the docs can come directly from the code because argument counts, names and types are always explicit (or deducable). These are just initial responses.

Re: Python documentation too difficult for beginners

2010-11-03 Thread Cameron Simpson
ot like javadoc. But its weakness is stuff like this: http://epydoc.sourceforge.net/stdlib/Canvas.Polygon-class.html Automatic docness, no useful information. And of course the ugliness; I find the python docs much nicer to look at. But I do wish the cross referencing was a bit better, often. --

Re: subprocess problem

2017-02-08 Thread Cameron Simpson
t. P.S. Tried also some code with invoking the bash and afterwords the which pandoc code. To know avail also From a shell prompt (such as bash's prompt) issuing the command: which pandoc should print the executable path, _if_ your $PATH includes the right directory. You can look at $PATH from the shell with the command: echo $PATH Do you know where pandoc normally resides on your system? Cheers, Cameron Simpson -- https://mail.python.org/mailman/listinfo/python-list

Re: subprocess problem

2017-02-09 Thread Cameron Simpson
. Cheers, Cameron Simpson -- https://mail.python.org/mailman/listinfo/python-list

Re: subprocess problem

2017-02-09 Thread Cameron Simpson
e(fullpath): return fullpath, True return "", False Cleaner is to return the path if found, or None if not. target, found = which("pandoc") if found: target will contain the full path to pandoc else: pandoc was not found You want to check for execute

Re: subprocess problem

2017-02-09 Thread Cameron Simpson
On 10Feb2017 00:03, eryk sun wrote: On Thu, Feb 9, 2017 at 10:50 PM, Cameron Simpson wrote: This is why I suggested the check_returncode() method, which examines the error code. You must be thinking of the returncode attribute, which isn't a method. check_returncode() is a method o

Re: subprocess problem

2017-02-10 Thread Cameron Simpson
y other interesting values that occur to you. This is really simple, and doesn't require a terminal or using the logging module. You can 'tail -f /path/to/your/logfile.txt' in another terminal to watch stuff happen as you exercise the program. Cheers, Cameron Simpson -- https://mail.python.org/mailman/listinfo/python-list

Re: python decorator

2017-02-21 Thread Cameron Simpson
tor that uses that cache. Like: def fun_cache(cache): def fun_cache_decorator(function): def wrapper(*args): ... save things in cache instead of memo ... return wrapper return fun_cache_decorator Cheers, Cameron Simpson -- https://mail.pytho

Re: Using re to perform grep functionality in Python

2017-03-01 Thread Cameron Simpson
example, have a gander at this: https://pypi.python.org/pypi/cs.app.megacli/20160310 which I wrote for IBM MegaRAIDs; it also does Dell PowerEdge (PERC) controllers. It is deliberately Python 2 BTW, because it had to run on RHEL 5 which had Python 2.4 as the vendor supplied python. Cheers

Re: Python question

2017-03-24 Thread Cameron Simpson
t, and doubly annoying to copy from that question into the list for replies. Thank you, Cameron Simpson -- https://mail.python.org/mailman/listinfo/python-list

Re: Python question

2017-03-26 Thread Cameron Simpson
to the email mailing list. If the OP had merely BCCed the mailing list, I wouldn't have received a copy in my personal inbox. Fair point. Though I thought I only got one copy, might be wrong. Cheers, Cameron Simpson -- https://mail.python.org/mailman/listinfo/python-list

Re: Program Error Help - Python 3.1

2017-03-31 Thread Cameron Simpson
; ): BTW, you need to decide whther you're working in strings or integers. input() in Python 3 returns a string. If you want to test against strings, fine. However, if you want to test against numbers you need to convert the string to a number: answer8n = int(answer8) and then test against answer8n. Cheers, Cameron Simpson -- https://mail.python.org/mailman/listinfo/python-list

python installs on OSX missing dbm.gnu

2017-04-01 Thread Cameron Simpson
ave such a thing and of course the python.org install is standalone. PyPI seems not forthcoming either. What should I be doing about this? Cheers, Cameron Simpson -- https://mail.python.org/mailman/listinfo/python-list

Re: VirtualEnvs (venv) and Powershell

2017-04-01 Thread Cameron Simpson
7; or even simpler: ( . /path/to/the/venv/bin/activate; exec $SHELL ) That would get you a prompt using the virtualenv by default. To reset to the old settings, exit that subshell. Maybe I misunderstand your needs. Cheers, Cameron Simpson -- https://mail.python.org/mailman/listinfo/python-list

Re: Merging multiple sorted sequences.

2017-04-12 Thread Cameron Simpson
dered. Insert and pop preserve that criterion. Cheers, Cameron Simpson -- https://mail.python.org/mailman/listinfo/python-list

Re: Test if Script Already Running

2017-04-19 Thread Cameron Simpson
ir else echo "lockdir already takens, aborting" >&2 exit 1 fi which means you don't need to fit the lock logic inside every tool, you can just do it in the script that calls them. Cheers, Cameron Simpson -- https://mail.python.org/mailman/listinfo/python-list

Re: tempname.mktemp functionality deprecation

2017-04-30 Thread Cameron Simpson
ir content (not actually unheard of)? > - some other solution I've missed? What about some variation on: from tempfile import NamedTemporaryFile ... with NamedTemporaryFile(dir=your_target_directory) as T: use T.name, and do your rename/unlink in here Cheers, Cameron Simpson

Re: tempname.mktemp functionality deprecation

2017-05-02 Thread Cameron Simpson
that. But Gregory Ewing's suggestion is much more direct. Cheers, Cameron Simpson -- https://mail.python.org/mailman/listinfo/python-list

Re: os.getlogin() Error

2017-05-04 Thread Cameron Simpson
around "who is logged in". Because the latter is not equivalent to "whose information should I access?" I hope this points a way forward. Personally I would usually resist accessing information not available as the user, and avoid the need to run as root at all. Cheers, Cameron Simpson -- https://mail.python.org/mailman/listinfo/python-list

Re: os.getlogin() Error

2017-05-04 Thread Cameron Simpson
On 04May2017 20:42, Wildman wrote: On Fri, 05 May 2017 09:00:58 +1000, Cameron Simpson wrote: On 04May2017 15:03, Wildman wrote: The program installs using the Debian package system (.deb) and an entry is created in the Applications Menu. The strange thing is that the crash only occurs when

Re: os.getlogin() Error

2017-05-05 Thread Cameron Simpson
ity decisions, particularly with things that automatically run as root. In particular, don't just think about how to get the behaviour you want; think about how to _break_ it - get root as the wrong person, or get root to give you information you should not have. Etc. Cheers, Cameron Simpson -- https://mail.python.org/mailman/listinfo/python-list

Re: getting the center of mass of each part of a molecule

2017-05-15 Thread Cameron Simpson
locate C1, and returns the left and right sublists. Cheers, Cameron Simpson -- https://mail.python.org/mailman/listinfo/python-list

Re: Concatenating files in order

2017-05-23 Thread Cameron Simpson
r filenames and the order they came back from the glob Try making these files in your test directory: foo foo_chunk_0 foo_chunk_1 foo_chunk_2 foo_chunk_10 and see what happens to your code. Temporarily drop the "with open..." and just print the filenames to see what order you would have processed the files. Cheers, Cameron Simpson -- https://mail.python.org/mailman/listinfo/python-list

Re: Concatenating files in order

2017-05-25 Thread Cameron Simpson
On 25May2017 20:37, Mahmood Naderan wrote: Cameron, thanks for the points. In fact the file name contains multiple '_' characters. So, I appreciate what you recommended. filenames = {} for name in glob.glob('*chunk_*'): left, right = name.rsplit('_', 1)

Re: Generator and return value

2017-06-07 Thread Cameron Simpson
hat would be a return value as the final item. Not very happy with it though. Cheers, Cameron Simpson -- https://mail.python.org/mailman/listinfo/python-list

Re: Customise the virtualenv `activate` script

2017-06-13 Thread Cameron Simpson
script, I'm leaning towards hacking the activate script, probably by keeping a distinct file off the the side and modifying activate to source it. Cheers, Cameron Simpson -- https://mail.python.org/mailman/listinfo/python-list

Re: Customise the virtualenv `activate` script

2017-06-16 Thread Cameron Simpson
s like it was made using virtualenv-3.5) and it has no hooks in the shell code, so Tim's stuff looks like it comes from virtualenvwrapper. Cheers, Cameron Simpson -- https://mail.python.org/mailman/listinfo/python-list

Re: Checking for an exception

2017-06-24 Thread Cameron Simpson
if isinstance(obj, type) else isinstance(obj, BaseException) ) ? Curious: why do you need to test this? Some function which may return a "value" or an exception? Cheers, Cameron Simpson -- https://mail.python.org/mailman/listinfo/python-list

Re: environment variable

2017-06-24 Thread Cameron Simpson
ear that he did indeed want to remove a single item from the things named in $PATH. He even provided example code showing exactly what he wanted to remove, and which demonstrated that he knew it was a colon separated string, which he was presenting as lines for purposes of clarity. Cheers, Cam

Re: Checking for an exception

2017-06-24 Thread Cameron Simpson
arly" kind of guy, and to me Steve's approach is in the same spirit as raising ValueError when a function is handed invalid arguments. Particularly if the mistake is easy to make, having one's attention brought to it immediately (at "declaration" time, since Steve'

Re: Teaching the "range" function in Python 3

2017-06-29 Thread Cameron Simpson
n iteration situations, with the for loop being the classic example. As a bonus, later you can use this paradigm when talking about generators and classes that implement "large but only computed on demand" things. Cheers, Cameron Simpson -- https://mail.python.org/mailman/listinfo/python-list

Re: Proper architecture

2017-07-02 Thread Cameron Simpson
) would go: def write(self, tickId: int): self.con.execute(blah) and as you can see that _removes_ any need to pass the connection back to the caller - you don't need to expose an reqConnection method at all, or manage it in the caller. Instead, ClassA can just store the DB instance itself, and let DB look after all the specifics. That is exactly the kind of thing class encapsulation is meant to achieve: the caller (Class A) can wash its hands of the mechanisms, which are not its problem. Cheers, Cameron Simpson -- https://mail.python.org/mailman/listinfo/python-list

Re: memory leak with re.match

2017-07-04 Thread Cameron Simpson
go of the match object "m" or of the line (which is probably attached to the match object "m" to support things like m.group() and so forth). So you might need to show us the handling code. Cheers, Cameron Simpson -- https://mail.python.org/mailman/listinfo/python-list

Re: Better Regex and exception handling for this small code

2017-07-11 Thread Cameron Simpson
on # but maybe no such lines is just normal but boring raise ValueError("no CRC lines seen in logfile %r" % (logfile,)) # found no changes return False See that there is very little sanity checking. In an exception supporting language like Python you can often

Re: Users of namedtuple: do you use the _source attribute?

2017-07-18 Thread Cameron Simpson
er in order to speed up namedtuple and reduce Python's startup time. Is there anyone here who uses the namedtuple _source attribute? Speaking for myself: no I do not. Cheers, Cameron Simpson -- https://mail.python.org/mailman/listinfo/python-list

Re: Validating regexp

2017-08-08 Thread Cameron Simpson
RE against a fixed empty string it is hard to be exploited. i.e. I think most of this stuff isn't expensive in terms of compiling the regexp but in executing it against text. Happy to hear to falsifications to my beliefs here. Cheers, Cameron Simpson (formerly c...@zip.com.au) -- https://mail.python.org/mailman/listinfo/python-list

Re: Validating regexp

2017-08-09 Thread Cameron Simpson
On 09Aug2017 10:46, Jon Ribbens wrote: On 2017-08-09, Cameron Simpson wrote: On 08Aug2017 17:31, Jon Ribbens wrote: ... but bear in mind, there have been ways of doing denial-of-service attacks with valid-but-nasty regexps in the past, and I wouldn't want to rely on there not being an

Re: A question on modification of a list via a function invocation

2017-08-16 Thread Cameron Simpson
Versus: o = o2 which changes which object the name "o" refers to ("is bound to"): it now refers to the second object we made. This is exactly analogous to the array example, but using objects. The notation eg "alist[1]" or "o.x" is just what you need to say to designate which reference you are changing. Cheers, Cameron Simpson (formerly c...@zip.com.au) -- https://mail.python.org/mailman/listinfo/python-list

Re: A question on modification of a list via a function invocation

2017-08-16 Thread Cameron Simpson
3] list, then modifies an unrelate new list. So "ss" is unchanged, still holding [1,2,3]. Then test modifies the original list (affecting what "ss" holds) and then points its local "alist" at something else (another shiny new list). But that doesn't change what "ss" refers to, so it now has [3,6,9]. Cheers, Cameron Simpson (formerly c...@zip.com.au) -- https://mail.python.org/mailman/listinfo/python-list

Re: A question on modification of a list via a function invocation

2017-08-16 Thread Cameron Simpson
k. This can lead to errors when a name is used within a block before it is bound. This rule is subtle. Python lacks declarations and allows name binding operations to occur anywhere within a code block. The local variables of a code block can be determined by scanning the entire text of the block for name binding operations." Cheers, Cameron Simpson (formerly c...@zip.com.au) -- https://mail.python.org/mailman/listinfo/python-list

Newbie: The philosophy behind list indexes

2013-06-14 Thread ian . l . cameron
I bet this is asked quite frequently, however after quite a few hours searching I haven't found an answer. What is the thinking behind stopping 'one short' when slicing or iterating through lists? By example; >>> a=[0,1,2,3,4,5,6] >>> a [0, 1, 2, 3, 4, 5, 6] >>> a[2:5] [2, 3, 4] To my mind,

Re: Newbie: The philosophy behind list indexes

2013-06-19 Thread ian . l . cameron
Thanks everyone for taking the time to offer some very insightful replies. Learning a new language is so much more fun with a group of friendly and helpful people around! -- http://mail.python.org/mailman/listinfo/python-list

Re: Pros and cons of Python sources?

2017-11-26 Thread nospam . Cameron Simpson
ould be done as root, and in this case that is easily avoided, with all its potential for damage to the vendor supplied environment. Cheers, Cameron Simpson (formerly c...@zip.com.au) -- https://mail.python.org/mailman/listinfo/python-list

Re: Argh!! Can't wrap my head around this Python stuff!

2017-11-26 Thread nospam . Cameron Simpson
l code (C++, Go, what have you). You can ship C code with Python to be compiled on the target and presented to Python as a library, and by convention such modules are named with a leading underscore. So we can expect that _imaging is a C code module. And if you go up a level you'll find _imaging.c, with a draw_ellipse function inside it. Cheers, Cameron Simpson (formerly c...@zip.com.au) -- https://mail.python.org/mailman/listinfo/python-list

Re: Pros and cons of Python sources?

2017-11-27 Thread nospam . Cameron Simpson
On 26Nov2017 10:00, nospam.Martin SchĶĶn wrote: >Den 2017-11-26 skrev Cameron Simpson : >> On 25Nov2017 08:34, rusi wrote: >>>On Saturday, November 25, 2017 at 9:45:07 PM UTC+5:30, Michael Torrie wrote: >>>> The problem with mixing repository-installed packages wi

Python Packages Survey

2019-01-18 Thread Cameron Davidson-Pilon
Hello! I invite you to participate in the Python Packages Survey - it takes less than a minute to complete, and will help open source developers understand their users' better. Thanks for participating! https://python-packages-survey.com/ -- Cameron Davidson-Pilon Data Origami &

Re: Argh!! Can't wrap my head around this Python stuff!

2017-11-26 Thread nospam . nospam . Cameron Simpson
l code (C++, Go, what have you). You can ship C code with Python to be compiled on the target and presented to Python as a library, and by convention such modules are named with a leading underscore. So we can expect that _imaging is a C code module. And if you go up a level you'll find _imaging.c, with a draw_ellipse function inside it. Cheers, Cameron Simpson (formerly c...@zip.com.au) -- https://mail.python.org/mailman/listinfo/python-list

Re: Should NoneType be iterable?

2023-06-20 Thread Cameron Simpson via Python-list
And of course I'm very -1 on None acquiring iteration or other features. Fail early, fail often! Cheers, Cameron Simpson -- https://mail.python.org/mailman/listinfo/python-list

Re: Should NoneType be iterable?

2023-06-20 Thread Cameron Simpson via Python-list
On 21Jun2023 10:09, Chris Angelico wrote: On Wed, 21 Jun 2023 at 09:59, Cameron Simpson via Python-list wrote: I wasted some time the other evening on an API which returned a string or None. My own API, and the pain it caused tells me that that API design choice isn't good (it's an

Re: isinstance()

2023-08-02 Thread Cameron Simpson via Python-list
e) There's similar language in this try/except documentation: file:///Users/cameron/var/doc/python/3.8.0/reference/compound_stmts.html#index-10 For an except clause with an expression, that expression is evaluated, and the clause matches the exception if the resulting object

Re: Where is the error?

2023-08-06 Thread Cameron Simpson via Python-list
er the underlined code? Is this "clairvoyant" behaviour a side-effect of the new parser or was that a deliberate decision? I have the vague impression the new parser enabled the improved reporting. Used to use a Pascal compiler once which was uncannily good at suggestin

Re: Where is the error?

2023-08-07 Thread Cameron Simpson via Python-list
On 07Aug2023 08:02, Barry wrote: On 7 Aug 2023, at 05:28, Cameron Simpson via Python-list wrote: Used to use a Pascal compiler once which was uncannily good at suggesting where you'd missing a semicolon. Was that on DEC VMS? It was a goal at DEC for its compilers to do this well.

Re: Imports and dot-notation

2023-08-09 Thread Cameron Simpson via Python-list
ble. But in a very long piece of code with many imports you might go for module1.funcname for clarity, particularly if funcname is generic or overlaps with another similar imported name. Cheers, Cameron Simpson -- https://mail.python.org/mailman/listinfo/python-list

Re: Why doc call `__init__` as a method rather than function?

2023-09-17 Thread Cameron Simpson via Python-list
ll it, the "bound method" knows that t is associated with `a` and puts that in as the first argument (usually named `self`). Cheers, Cameron Simpson -- https://mail.python.org/mailman/listinfo/python-list

Re: Where I do ask for a new feature

2023-10-19 Thread Cameron Simpson via Python-list
On 19Oct2023 20:16, Bongo Ferno wrote: A with statement makes clear that the alias is an alias and is local, and it automatically clears the variable after the block code is used. No it doesn't: >>> with open('/dev/null') as f: ... print(f) ... <_io.TextIOWrapper name='/dev/

Re: return type same as class gives NameError.

2023-10-22 Thread Cameron Simpson via Python-list
This message: NameError: name 'Pnt' is not defined. Did you mean: 'PNT'? is unfortunate, because you have a very similar "PNT" name in scope. But it isn't what you want. Cheers, Cameron Simpson -- https://mail.python.org/mailman/listinfo/python-list

Re: Checking if email is valid

2023-11-01 Thread Cameron Simpson via Python-list
special unique and opaue URL,please visit it to confirm receipt of this email (implying email is 'real"). You see this a lot when signing up for things. And for plenty of things I generate a random throw away address at mailinator.com (looking at you, every "catch up" free o

Re: Checking if email is valid

2023-11-01 Thread Cameron Simpson via Python-list
/rfc2821#section-4.1.1.6 I think a lot of mail receivers don't honour this one, for exactly the reasons above. Cheers, Cameron Simpson -- https://mail.python.org/mailman/listinfo/python-list

Re: Newline (NuBe Question)

2023-11-15 Thread Cameron Simpson via Python-list
grades.append(s.name) grades.append(s.finalGrade()) if s.finalGrade()>82: grades.append("Pass") else: grades.append("Fail") print(grades) Cheers, Cameron Simpson -- https://mail.python.org/mailman/listinfo/python-list

Re: Type hints - am I doing it right?

2023-12-13 Thread Cameron Simpson via Python-list
ince I imagine config_database() would accept any kind of mapping (dicts, etc etc). Cheers, Cameron Simpson -- https://mail.python.org/mailman/listinfo/python-list

Re: How would you name this dictionary?

2024-01-21 Thread Cameron Simpson via Python-list
On 21Jan2024 23:39, bagra...@live.com wrote: class NameMe(dict): def __missing__(self, key): return key I would need to know more about what it might be used for. What larger problem led you to writing a `dict` subclass with this particular `__missing__` implementation? -- https:/

Re: Is there a way to implement the ** operator on a custom object

2024-02-08 Thread Cameron Simpson via Python-list
On 08Feb2024 12:21, tony.fl...@btinternet.com wrote: I know that mappings by default support the ** operator, to unpack the mapping into key word arguments. Has it been considered implementing a dunder method for the ** operator so you could unpack an object into a key word argument, and the

<    19   20   21   22   23   24   25   >