Re: Checking support for network connections from Python client to IPv6 server

2019-06-02 Thread Cameron Simpson
hon.org/3/library/socket.html#socket.create_connection I think I'm with Chris here: by using AF_INET you're saying "IPv4 only please". "::1" is not an IPv4 address. hence your error. It's not called "AF_INET4" because it predates IPv6. The function Chr

Re: new to python - like to write a script with the libvirt-python 5.3.0 package

2019-06-03 Thread Cameron Simpson
an system, apt-get appears to be able to find something [...] Using the API means you will not be invoking "virsh" commands themselves. You will have to become familiar with the API equivalent to the commands you were using. Or he could just "python3 -m pip install libvirt-python

Re: FDs will be closed after exception automatically in python2.7?

2019-06-10 Thread Cameron Simpson
vel open, getting a fie descriptor. The opening function raises an exception. After we've caught it, we run "lsof" on our own process. here's it on my Mac: [~]fleet*1> /usr/bin/python fd.py COMMAND PIDUSER FD TYPE DEVICE SIZE/OFF NODE NA

The trailing comma bites! You have a new tuple.

2019-06-13 Thread Cameron Simpson
rpath ), task = IngestTask(..., logical_dirpath=logical_dirpath, ...) Typing badness ensues. In a subsequent function call far far away. Grumble, Cameron Simpson -- https://mail.python.org/mailman/listinfo/python-list

Re: What's the latest best practice on Python project directory layouts?

2019-06-14 Thread Cameron Simpson
es you make. Happy to elaborate on specifics, though they get more personal and idiosyncratic the more fine grained we get. Cheers, Cameron Simpson -- https://mail.python.org/mailman/listinfo/python-list

Re: Python refactoring question and create dynamic attributes

2019-06-23 Thread Cameron Simpson
ll seem written to use self, and thus be instance methods. Cheers, Cameron Simpson -- https://mail.python.org/mailman/listinfo/python-list

Re: for line3 in myips matching too longer matches.

2019-06-26 Thread Cameron Simpson
and comparison), so the nature of the test is driven by the type of the object being tested (on the right, for "in")). So... address = line1.rstrip('\n') words = line2.split() if address in words: ... Personally I'd be being pickier about line1 as well, but ifyour input is well defined that may not matter. Cheers, Cameron Simpson -- https://mail.python.org/mailman/listinfo/python-list

Re: Only a message at the highest exception

2019-06-28 Thread Cameron Simpson
try: appended = append_row() except Exception as err: messagebox.showerror() else: if appended: hooray! else: unhappy, but continuing avoiding a "do nothing" special except clause. Cheers, Cameron Simpson -- https://mail.python.org/mailman/listinfo/python-list

Re: change spacing to two instead of four with pep8 or flake8?

2019-06-28 Thread Cameron Simpson
sonal lint script: https://bitbucket.org/cameron_simpson/css/src/tip/bin-cs/lint My personal format script: https://bitbucket.org/cameron_simpson/css/src/tip/bin-cs/format Take what you'd like. Cheers, Cameron Simpson -- https://mail.python.org/mailman/listinfo/python-list

Re: change spacing to two instead of four with pep8 or flake8?

2019-06-29 Thread Cameron Simpson
On 29Jun2019 10:19, Malcolm Greene wrote: I've also taken to having my files auto-formatted with yapf on save ... @Cameron: Have you considered black at all and if so, what are your thoughts? I did consider black. Its core selling point was its total inflexibility. Use this and

Re: Do I need a parser?

2019-07-01 Thread Cameron Simpson
er (though much more work) to devise a simple script language which you parse and turn into some kind of rule system. That way the semantics are constrained. Cheers, Cameron Simpson -- https://mail.python.org/mailman/listinfo/python-list

Re: What's wrong on using Popen's communicate method?

2019-07-03 Thread Cameron Simpson
noring your input data - this approach will generally fail with any desktop app on any platform. You may need to investigate generating synthetic keystrokes somehow. Or alternatively write your data to a text file and hand the name of the text file to notepad as a file to edit. Che

Re: Embedding classes' names

2019-07-16 Thread Cameron Simpson
lf).__name__" for no totally rational reason. Cheers, Cameron Simpson -- https://mail.python.org/mailman/listinfo/python-list

Re: Proper shebang for python3

2019-07-20 Thread Cameron Simpson
ou. If your tools are strongly affected by version, run them with an environment that finds the right version. Installers, particularly those run as root or in other low level setup situations, should have a WELL DEFINED environment. If you have a tool that isn't portable, put it in

Re: Proper shebang for python3

2019-07-20 Thread Cameron Simpson
On 21Jul2019 09:31, Chris Angelico wrote: On Sun, Jul 21, 2019 at 9:15 AM Cameron Simpson wrote: So you mean that a tool that depends on running on a consistent environment, it should use a shebang of "/usr/bin/python3.6" instead of "/usr/bin/env python3"? J

Re: Proper shebang for python3

2019-07-21 Thread Cameron Simpson
On 21Jul2019 15:47, Peter J. Holzer wrote: On 2019-07-21 09:04:43 +1000, Cameron Simpson wrote: I'm with Tim Daneliuk. The environment matters and should be honoured except in extremely weird cases. I don't think that all the scripts in /usr/bin are extremely weird cases. I

Re: Proper shebang for python3

2019-07-22 Thread Cameron Simpson
on V7 UNIX, well older than Solaris. Figuring out where things are on the user's path is a laudable goal, but do it only at install time, not run time, for consistent runs. Perhaps. Consistent runs require consistent environments. That often includes executables. Cheers, Cameron Simpson -- https://mail.python.org/mailman/listinfo/python-list

Re: Proper shebang for python3

2019-07-22 Thread Cameron Simpson
ython. Cheers, Cameron Simpson -- https://mail.python.org/mailman/listinfo/python-list

Re: Nesting Custom Errors in Classes

2019-07-23 Thread Cameron Simpson
nsensical. I have use nested classes when the nested class is strongly associated with the enclosing class, like your classname.exceptionname example. I'd put it inside the outer class entirely to express that association. Cheers, Cameron Simpson -- https://mail.python.org/mailman/listinfo/python-list

Re: Nesting Custom Errors in Classes

2019-07-23 Thread Cameron Simpson
ror. The tricky bit with dynamic language like Python is that some naming errors (missed imports) aren't apparent until the code passes through that path. Linters can cover a lot of this with static analysis. Cheers, Cameron Simpson -- https://mail.python.org/mailman/listinfo/python-list

Re: Nesting Custom Errors in Classes

2019-07-23 Thread Cameron Simpson
On 24Jul2019 11:47, DL Neil wrote: On 24/07/19 10:07 AM, Cameron Simpson wrote: On 24Jul2019 07:21, DL Neil wrote: ... Get some linting tools. They're great for catching this kind of error. SublimeText has SublimeLinter and PycodeStyle installed, but I'm still familiarising m

Re: Proper shebang for python3

2019-07-24 Thread Cameron Simpson
On 24Jul2019 21:36, Barry Scott wrote: On 23 Jul 2019, at 00:13, Cameron Simpson wrote: Why _any_ modern system has anything other than /bin in the base install escapes me. In the distant past /sbin and a distinct /usr with its own bin had their values, but these days? Bah! On fedora its

Re: Hermetic environments

2019-07-24 Thread Cameron Simpson
rver machine; it contains a specific Python venv inside it; the upper layer is the encapsulation. Example: STAGING -> app/version2 app-version venv/ webapp/javascript-here... ... app-version2 venv/ webapp/javascript-here... ... I still want the venv because it enca

Re: Proper shebang for python3

2019-07-24 Thread Cameron Simpson
On 24Jul2019 20:24, Michael Torrie wrote: On 7/24/19 4:20 PM, Cameron Simpson wrote: That is some progress, hooray. Then there's just sbin -> bin to go. I suppose in the olden days sbin was for static binaries, usable in single user mode for recovering the system without the ma

Re: Hermetic environments

2019-07-24 Thread Cameron Simpson
why would you prefer to set up a second and separate py-env within an existing environment? 1: it is smaller and much lower overhead. How many _live_ VMs are you keeping around? 2: no VMs in play at this end. Cheers, Cameron Simpson -- https://mail.python.org/mailman/listinfo/python-list

Re: Proper shebang for python3

2019-07-25 Thread Cameron Simpson
ight have made that change myself. My .shrc file has all sorts of leftovers from the old days, but my current Linux PATH is just $HOME/bin, $HOME/local/bin, and /usr/bin. Hmm. 21 componetent in my $PATH here :-) Cheers, Cameron Simpson -- https://mail.python.org/mailman/listinfo/python-list

Re: Difference between os.path.isdir and Path.is_dir

2019-07-25 Thread Cameron Simpson
and I think also the NAS were UNIX/Linux at each end, but speaking over SMB.) Guessing that the NAS was doing only a half hearted implementation of the trailing spaces semantics. Interesting:-) Cheers, Cameron Simpson -- https://mail.python.org/mailman/listinfo/python-list

Re: Difference between os.path.isdir and Path.is_dir

2019-07-25 Thread Cameron Simpson
me for Path(" "), depending on whether a directory named " " exists (normally not allowed in Windows, but Linux allows it). Try an empty string, no spaces. To pathlib.Path, that means the current directory. To os.path.abspath, that means the current directory. To os.stat, it

Re: Definite or indefinite article for non-singletons?

2019-07-27 Thread Cameron Simpson
le? For instance, would you say "the empty string" but "an empty set"? If the implementation _may_ fold indistinguishable things together I'd speak to the case that it may not, and say "if the string is empty", which (a) sidesteps whether there's only one emp

Re: Definite or indefinite article for non-singletons?

2019-07-28 Thread Cameron Simpson
expect to frob the things passed as the parameter (thus, the context). Versus: class Thing: ... def f(s): ''' Frob all Things. ''' I would expect there to be some global registry of Thing instances, and to frob them all. Chris' example is a bit incomplete because there's no context to indicate what group "the things" comprise. Cheers, Cameron Simpson -- https://mail.python.org/mailman/listinfo/python-list

Re: Definite or indefinite article for non-singletons?

2019-07-28 Thread Cameron Simpson
On 28Jul2019 20:11, Richard Damon wrote: On 7/28/19 11:13 AM, MRAB wrote: On 2019-07-28 13:30, Cameron Simpson wrote: The collection is "the things". "all" qualifies it, versus, say, "some of the things" or "the first of the things" etc. [snip] It&

Re: Definite or indefinite article for non-singletons?

2019-07-28 Thread Cameron Simpson
s effectively naming a category of sets (those of size 0) and considering that a single thing in that context. I'm for running with "values" in the example you started with. I think the "the empty string" is mathematical context specific terminology leaking into the wrong domain. Cheers, Cameron Simpson -- https://mail.python.org/mailman/listinfo/python-list

Re: Is there a simple way to wrap a built-in function for the whole package?

2019-08-01 Thread Cameron Simpson
. import open8 and use "open8" throughout the code instead of "open"? What not alias "open"? Because I would want it evident that in this code we're doing a slightly special flavour of open. By using a distinct name I avoid confusion about the

Re: Remote/Pair-Programming in-the-cloud

2019-08-02 Thread Cameron Simpson
lve the keep-the-code-in-sync issue. Cheers, Cameron Simpson -- https://mail.python.org/mailman/listinfo/python-list

Re: Remote/Pair-Programming in-the-cloud

2019-08-02 Thread Cameron Simpson
On 03Aug2019 16:51, DL Neil wrote: On 3/08/19 11:50 AM, Cameron Simpson wrote: appear.in can also screen share along with its video conferencing, and I imagine Zoom might do so also. But a screen share is "read only" for the other party. You could both screen share of course, but

Re: Remote/Pair-Programming in-the-cloud

2019-08-02 Thread Cameron Simpson
) then you always need an external intermediary. Even if that intermediary does no more than connect some sockets from each end together and blindly pass traffic. Cheers, Cameron Simpson -- https://mail.python.org/mailman/listinfo/python-list

Re: Why they use this: duration = time.time() - self.start_time + 1

2019-08-03 Thread Cameron Simpson
e same for duration but they do not. Cheers, Cameron Simpson -- https://mail.python.org/mailman/listinfo/python-list

Re: Python/SQLite best practices

2019-08-05 Thread Cameron Simpson
backends, so you could switch backends later (eg from SQLite to PostgreSQL) if that becomes a thing. Cheers, Cameron Simpson -- https://mail.python.org/mailman/listinfo/python-list

Re: Python in Blender. Writing information to a file.

2019-08-08 Thread Cameron Simpson
..print..close" sequence would not reach the close call. So we recommend the "with" form of open() above. There are circumstances where it isn't useful, but they are very rare. Cheers, Cameron Simpson -- https://mail.python.org/mailman/listinfo/python-list

Re: Python in Blender. Writing information to a file.

2019-08-09 Thread Cameron Simpson
ote: with open("/path/to/file", "w") as outstream:   print(my_stuff, file=outstream) Got it! I hadn't taken Peter's advice as code. I thought (well anyway now I have it). So thanks to Peter, Cameron and Rhodri. No worries. You should also got and look up "co

Re: String slices

2019-08-09 Thread Cameron Simpson
dings are causing you inconvenience. Personally, for text output, I use print unless there's some compelling reason not to (such as transcribing a data structure precisely, not wanting unexpected spaces and newlines; if I were hand transcribing JSON or XML or HTML or the like). Cheers, Cameron Simpson -- https://mail.python.org/mailman/listinfo/python-list

Re: class definition question

2019-08-10 Thread Cameron Simpson
ython 2, the bare MyClass: is indeed preferable. However, a lot of my code is in modules which might conceivably be used by anyone. Artificially contraining their use seems counterproductive. Cheers, Cameron Simpson -- https://mail.python.org/mailman/listinfo/python-list

Re: Web framework for static pages

2019-08-12 Thread Cameron Simpson
re are several out there. I haven't any experience with which to offer an opinion though. Cheers, Cameron Simpson -- https://mail.python.org/mailman/listinfo/python-list

Re: Fwd: Startup problems

2019-08-13 Thread Cameron Simpson
ystem and where you obtained your ptyhon install, and what you did to start IDLE. Otherwise we do not have enough context to assist. Cheers, Cameron Simpson -- https://mail.python.org/mailman/listinfo/python-list

Re: absolute path to a file

2019-08-15 Thread Cameron Simpson
s.path.realpath(filename) for this purpose. In modern Python that also accepts a Pathlike object. Cheers, Cameron Simpson -- https://mail.python.org/mailman/listinfo/python-list

Re: absolute path to a file

2019-08-17 Thread Cameron Simpson
ath library function is relevant. 2: What is your current working directory when you run this code? If the underlying OS realpath fails, the Python library function might fall back on os.path.join(os.getcwd(), filename). 3: What is the airspeed velocity of an unladen swallow? https://www.pyth

Re: absolute path to a file

2019-08-18 Thread Cameron Simpson
Paul, I can see we must train you in the interleaved response style :-) On 18Aug2019 17:29, Paul St George wrote: On 18/08/2019 02:03, Cameron Simpson wrote: 1: Is image01.tif a real existing file when you ran this code? Yes. image01.tif is real, existing and apparent. But in what directory

Re: absolute path to a file

2019-08-19 Thread Cameron Simpson
On 19Aug2019 08:52, Paul St George wrote: On 19/08/2019 01:31, Cameron Simpson wrote: On 18Aug2019 17:29, Paul St George wrote: On 18/08/2019 02:03, Cameron Simpson wrote: 1: Is image01.tif a real existing file when you ran this code? Yes. image01.tif is real, existing and apparent. But in

Re: absolute path to a file

2019-08-20 Thread Cameron Simpson
Please remember to CC the list. On 19Aug2019 22:06, Paul St George wrote: On 19/08/2019 14:16, Cameron Simpson wrote: [...] There's a remark on that web page I mentioned that suggests that the leading '//' indicates the filename is relative to the Blender model, so the contex

Re: absolute path to a file

2019-08-20 Thread Cameron Simpson
On 20Aug2019 21:06, Paul St George wrote: On 20/08/2019 11:43, Cameron Simpson wrote: Please remember to CC the list. Instead of 'Post a followup to this newsgroup' or 'To: python-list@python.org'? Hmm. I've been getting some of your posts directly to me as emai

Re: Newbie question about Python syntax

2019-08-22 Thread Cameron Simpson
odeMapValue. That instance should have a .max array. Cheers, Cameron Simpson -- https://mail.python.org/mailman/listinfo/python-list

Re: How should we use global variables correctly?

2019-08-22 Thread Cameron Simpson
ewhere. However, if you have a good case for using a global, always use the "global" statement. It has the following benefits: it makes the globalness obvious to the person reading the code and it avoids a global variable suddenly becoming local if you assign to it. (NB: the "time" of that semantic change is when you change the code, _not_ when the assignment itself happens.) Cheers, Cameron Simpson -- https://mail.python.org/mailman/listinfo/python-list

Re: How to record the console's content in the interpreter?

2019-08-22 Thread Cameron Simpson
an run the 'script" command. This starts a new shell inside a session which records itself to the file "typescript" (by default). See "man script" for further details. Cheers, Cameron Simpson -- https://mail.python.org/mailman/listinfo/python-list

Re: How to record the console's content in the interpreter?

2019-08-22 Thread Cameron Simpson
On 22Aug2019 21:48, Jach Fong wrote: Cameron Simpson於 2019年8月23日星期五 UTC+8下午12時09分54秒寫道: On 22Aug2019 19:38, Jach Fong wrote: >Say I like to record everything showing in the console into a file >after I start a debug session, and stop it when finished. It's not >a console redire

Re: How should we use global variables correctly?

2019-08-23 Thread Cameron Simpson
), they are pretty much the same. Or I missed something? Making a class level name has the nice aspect that it has a better conceptual context. Cheers, Cameron Simpson -- https://mail.python.org/mailman/listinfo/python-list

Re: How should we use global variables correctly?

2019-08-23 Thread Cameron Simpson
e class, not an instance. The terminology is important. Cheers, Cameron Simpson -- https://mail.python.org/mailman/listinfo/python-list

Re: Newbie question about Python syntax

2019-08-23 Thread Cameron Simpson
def probe(o): print(o) for attr, value in sorted(o.__dict__.items()): print(" ", attr, type(value).__name__, value) Enjoy, Cameron Simpson (formerly c...@zip.com.au) "Are we alpinists, or are we tourists" followed by "tourists! tourists!" - Kobus

Re: Newbie question about Python syntax

2019-08-24 Thread Cameron Simpson
builtin Python function), it seems that one creates one of these to control how some rendering process is done. The class reference page you originally cites then specifies the meaning of the various attributes you might set on one of these objects. Cheers, Cameron Simpson -- https://mail.python.org/mailman/listinfo/python-list

Re: if STREAM.isatty():

2019-08-29 Thread Cameron Simpson
ise that the output is a normal text file, such as a log file. So it just wants to write normal lines of text. Cheers, Cameron Simpson -- https://mail.python.org/mailman/listinfo/python-list

Re: if STREAM.isatty():

2019-08-30 Thread Cameron Simpson
he describes is entirely possible on UNIX. Cheers, Cameron Simpson -- https://mail.python.org/mailman/listinfo/python-list

Re: if STREAM.isatty():

2019-08-30 Thread Cameron Simpson
On 31Aug2019 08:57, Cameron Simpson wrote: On 30Aug2019 10:25, Michael Torrie wrote: On Fri, Aug 30, 2019, 05:02 Hongyi Zhao On Fri, 30 Aug 2019 17:53:02 +1000, Chris Angelico wrote: (Also, why the sleep? Seems unnecessary.) Because without using sleep, the stuff on screen will display

Re: Pygal bar colors

2019-08-31 Thread Cameron Simpson
, and I've never used pygal. Cheers, Cameron Simpson -- https://mail.python.org/mailman/listinfo/python-list

Re: Execute complex shell commands within python and obtain the output.

2019-09-02 Thread Cameron Simpson
8 based. It probably is, but if it isn't then you may get mojibake. Cheers, Cameron Simpson -- https://mail.python.org/mailman/listinfo/python-list

Re: PYTHON DIDNT DETECTED

2019-09-02 Thread Cameron Simpson
t; from your command prompt works...] I would guess that you hare put the command "python" _inside_ a python script. The command "python" is for use _outside_ the script, to invoke the script. We'd need to see what you did, and your script, to offer better advice. C

Re: Append some stuff into a file with only the last appended line reserved.

2019-09-02 Thread Cameron Simpson
hould land in the log file. Cheers, Cameron Simpson -- https://mail.python.org/mailman/listinfo/python-list

Re: Execute complex shell commands within python and obtain the output.

2019-09-03 Thread Cameron Simpson
On 03Sep2019 03:59, Hongyi Zhao wrote: On Tue, 03 Sep 2019 08:24:17 +1000, Cameron Simpson wrote: Finally, the .decode('utf8') assumes your locale is UTF8 based. It probably is, but if it isn't then you may get mojibake. Nowadays, most of the os use utf8 as the default loca

Re: Renaming an import

2019-09-05 Thread Cameron Simpson
graphing_module_b as graph pkg/foobar.py from . import graph plot = graph.plot axis = graph.axis Alternatively: pkg/__init__.py import graphing_module_b as graph plot = graph.plot axis = graph.axis pkg/foobar.py from . import graph, plot, axis Cheers, Cameron Simpson

Re: Multidimensional dicts

2019-09-06 Thread Cameron Simpson
re the key2 values for key1==x?" then you might want a tree structure. The ddd_a (key1,key2) approach is easier to manage in terms of creating new nodes. OTOH, using a nested defaultdict can handle that work for you: ddd_d = defaultdict(lambda: defaultdict(int)) (Pick a suitable

Re: WedWonder: Scripts and Modules

2019-09-11 Thread Cameron Simpson
really common. Even for my current client project, which is largely a package, several of the individual modules within the package have their own main programmes for testing and for various utility tasks dealing solely with that particular subsystem. There's an overarching shell sc

Re: WedWonder: Scripts and Modules

2019-09-12 Thread Cameron Simpson
On 13Sep2019 08:40, DL Neil wrote: On 12/09/19 10:59 AM, Cameron Simpson wrote: On 12Sep2019 08:24, DL Neil wrote: In this day-and-age do you have a script in live/production-use, which is also a module? What is the justification/use case? Many. Many many. 1: Many of my modules run their

Re: Friday Finking: 'main-lines' are best kept short

2019-09-13 Thread Cameron Simpson
d also distinguish between project-versions, if relevant. More importantly, changes to application version numbers do not require any changes to import statements! (and when users don't wish to be expected to remember version numbers "as well", use symlinks - just as we do with python/python2/python3/python3.7... Note that it has become unnecessary to add the -m switch! The -m switch is my friend. It says "obey the sys.path", so that I can control things courtesy of the sys.path/$PYTHONPATH. Cheers, Cameron Simpson -- https://mail.python.org/mailman/listinfo/python-list

Re: The differences between json.dumps and json.loads.

2019-09-13 Thread Cameron Simpson
and returns an object. "Load from string". Cheers, Cameron Simpson (formerly c...@zip.com.au) -- https://mail.python.org/mailman/listinfo/python-list

Re: Bool variable with json.dumps

2019-09-15 Thread Cameron Simpson
s Python values into JavaScript syntax. This is likely to be the same reason you were wondering about None vs null; broadly, the Python None value serves the same purpose as the JavaScript null value, and therefore that is how it is expressed in JSON. Cheers, Cameron Simpson -- https://mail.python.

Re: Irritating bytearray behavior

2019-09-16 Thread Cameron Simpson
o the bytearray without changing its size? Sure: msg[4:4+len(ip.packed)] = ip.packed What you did was ask to replace all the bytes from 4 onward. What you should do is replace just the correct bytes. Cheers, Cameron Simpson -- https://mail.python.org/mailman/listinfo/python-list

Re: python3 subprocess run sudo cmd in remote failed

2019-09-16 Thread Cameron Simpson
e? Also, try doing this without shell=True - it is an invitation for mistakes and shell injection (depending on your uses). Cheers, Cameron Simpson -- https://mail.python.org/mailman/listinfo/python-list

Re: python3 subprocess run sudo cmd in remote failed

2019-09-16 Thread Cameron Simpson
11's password: It always prompt immediately, that make me hard to enter password. Well ssh will be connected to your terminal. Do things work if you hand type the password at that point? Maybe I should try paramiko... Or pexpect. But use a keypair - it will simplify your life, and generally be far more secure anyway. Cheers, Cameron Simpson -- https://mail.python.org/mailman/listinfo/python-list

Re: Obtain the file's path.

2019-09-17 Thread Cameron Simpson
symlink into our larger RAID array. So abspath(expanduser("~/media/foo.mp4")) might expand to "/home/cameron/media/foo.mp4". Conversely, realpath(expanduser("~/media/foo.mp4")) might expand to "/raid_volume/cameron/media/foo.mp4". If I rearrange things, fo

Re: Obtain the file's path.

2019-09-18 Thread Cameron Simpson
On 18Sep2019 03:36, eryk sun wrote: On 9/17/19, Cameron Simpson wrote: If you just want this for your running program's internals this may not matter, but if you're recording the result somewhere then abspath might get you a more "stable" path in the above scena

Re: [Tutor] Most efficient way to replace ", " with "." in a array and/or dataframe

2019-09-21 Thread Cameron Simpson
" for the thousands marker), you want to set the "decimal=" parameter of read-csv to ",". This is better than trying to mangle the data yourself, better to just correctly specify the dialect (i.e. set decimal= in your call). Cheers, Cameron Simpson -- https://mail.python.org/mailman/listinfo/python-list

Re: [Tutor] Most efficient way to replace ", " with "." in a array and/or dataframe

2019-09-22 Thread Cameron Simpson
On 22Sep2019 07:39, Albert-Jan Roskam wrote: On 22 Sep 2019 04:27, Cameron Simpson wrote: On 21Sep2019 20:42, Markos wrote: I have a table.csv file with the following structure: , Polyarene conc ,, mg L-1 ,,, Spectrum, Py, Ace, Anth, 1, "0,456", "0,120", "

Re: python installation.

2019-09-23 Thread Cameron Simpson
what installer you chose. Disclaimer: not a Windows person. Cheers, Cameron Simpson -- https://mail.python.org/mailman/listinfo/python-list

Re: CSV reader ignore brackets

2019-09-24 Thread Cameron Simpson
for line in f: fields = split_line(line) rows.append(fields) So basicly you're writing a little parser. If you have nested brackets things get harder. Cheers, Cameron Simpson -- https://mail.python.org/mailman/listinfo/python-list

Re: CSV reader ignore brackets

2019-09-24 Thread Cameron Simpson
reader will "just work". Again, nesting parens not allowed. Otherwise, a neat idea. Besides, the point isn't the shortest code but to illustrate the idea of handling special syntax. Cheers, Cameron Simpson -- https://mail.python.org/mailman/listinfo/python-list

Re: Delay in python startup.

2019-09-30 Thread Cameron Simpson
. Thanks for helping me figure this out. For the future: you can often see something this slow with an strace: strace python Watch what it is doing when it stalls. Cheers, Cameron Simpson -- https://mail.python.org/mailman/listinfo/python-list

Re: ipython in different loctions.

2019-10-02 Thread Cameron Simpson
is is the Python boilerplate wrapper with pip uses to install an ipython executable script in a bin directory. You may find that the shell script from .pyenv/shims eventually executes a python script like the one from .local/bin. Try going: bash -x ~/.pyenv/shims/ipython3 and see what its f

Re: uses both shell and python codes in one script.

2019-10-03 Thread Cameron Simpson
just a dummy "true" command, with a comment. Since I'm here, I'll seize the opportunity to endorse Chris' earlier statement: just use "#!/usr/bin/env python3" as the opening shebang line and don't worry about embedding complex shell to "locate" python. Instead, expect the caller's environment to be correctly set up, and therefore for the "python3" command to find the preferred python interpreter. Cheers, Cameron Simpson -- https://mail.python.org/mailman/listinfo/python-list

Re: uses both shell and python codes in one script.

2019-10-03 Thread Cameron Simpson
Rather than complex magic inside a script. If we're going to accept the approach though, I'd rather the shebang was just "#!/bin/sh". There's _always_ a /bin/sh, and a number of BSDish systems do not have a /usr/bin/env (it tends to land in /bin instead). Cheers, Cameron Si

Re: uses both shell and python codes in one script.

2019-10-03 Thread Cameron Simpson
On 04Oct2019 09:17, Chris Angelico wrote: On Fri, Oct 4, 2019 at 9:13 AM Cameron Simpson wrote: If we're going to accept the approach though, I'd rather the shebang was just "#!/bin/sh". There's _always_ a /bin/sh, and a number of BSDish systems do not have a /usr/

Re: ipython in different loctions.

2019-10-05 Thread Cameron Simpson
On 03Oct2019 00:45, Hongyi Zhao wrote: On Thu, 03 Oct 2019 10:19:23 +1000, Cameron Simpson wrote: bash -x ~/.pyenv/shims/ipython3 and see what its final command does. Tried as follows: - werner@localhost:~$ bash -x ~/.pyenv/shims/ipython3 [...] + exec /home/werner/.pyenv

Re: python -m pip install and pip install

2019-10-07 Thread Cameron Simpson
sing what you just installed. It isn't a deal breaker, but preferred: one less moving part. Cheers, Cameron Simpson -- https://mail.python.org/mailman/listinfo/python-list

Re: How to handle '-' in the 'from' part in a "from import" statement?

2019-10-08 Thread Cameron Simpson
). So the symlink thing is not unreasonable at all. Cheers, Cameron Simpson -- https://mail.python.org/mailman/listinfo/python-list

Re: Odd delays when cwd is on a network mount

2019-10-11 Thread Cameron Simpson
le.py Without the os.chdir() the import is instantaneous. Python's default sys.path includes the current working directory. (Worse: at the front!) So it is loooking for my_module in the sshfs directory before your standard places. Thus the slowness. Personally I consider this a misfeatu

Re: Odd delays when cwd is on a network mount

2019-10-11 Thread Cameron Simpson
On 12Oct2019 14:04, Greg Ewing wrote: Cameron Simpson wrote: Python's default sys.path includes the current working directory. Only in an interactive session, where it usually makes sense. Personally, I would not consider this: % python3 -c 'import sys;print(rep

Re: Odd delays when cwd is on a network mount

2019-10-14 Thread Cameron Simpson
On 14Oct2019 10:06, Tobiah wrote: On 10/11/19 6:04 PM, Gregory Ewing wrote: Cameron Simpson wrote: Python's default sys.path includes the current working directory. Only in an interactive session, where it usually makes sense. I was only using the REPL for demonstration. The same

Re: Black

2019-10-21 Thread Cameron Simpson
wrote: > I've also taken to having my files auto-formatted with yapf on save > ... @Cameron: Have you considered black at all and if so, what are your thoughts? I did consider black. Its core selling point was its total inflexibility. Use this and stop _caring_ about the formatting:

Re: What's the difference between running a script under command box and interpreter?

2019-10-31 Thread Cameron Simpson
applies with most other functions: if they all require their external state via parameters then you can't miss things out. (You can, of course, always pass incorrect values, but that is usually easier to debug.) Avoid globals; they are usually a source of bugs. Cheers, Cameron Simpson -- https://mail.python.org/mailman/listinfo/python-list

Re: What's the difference between running a script under command box and interpreter?

2019-11-01 Thread Cameron Simpson
On 31Oct2019 22:03, Jach Fong wrote: Cameron Simpson於 2019年11月1日星期五 UTC+8下午12時13分45秒寫道: On 31Oct2019 20:44, Jach Fong wrote: >The script test.py is something like this: >---test.py >from pyeds import fsm >... >class Rule_Parse: >

Re: What's the difference between running a script under command box and interpreter?

2019-11-03 Thread Cameron Simpson
k. How should python know that you want to set the rule variable in the test module? My 'wrong' answer will be, at the time I raised my question, that when import two different modules either has 'rule' variable, REPL will see the second imported one. No kidding:-) We

Re: How execute at least two python files at once when imported?

2019-11-06 Thread Cameron Simpson
safe. Provided the imported modules do only local work it should be safe. Spencer's modules run unconditional stuff in addition to defining classes. That may cause trouble. Cheers, Cameron Simpson -- https://mail.python.org/mailman/listinfo/python-list

Re: How execute at least two python files at once when imported?

2019-11-06 Thread Cameron Simpson
nctions from each module. If those main functions do not share data it will probably all just work. If they do share data then you may need to debug some synchronisation issues; it depends on the code itself. Cheers, Cameron Simpson -- https://mail.python.org/mailman/listinfo/python-list

<    4   5   6   7   8   9   10   11   12   13   >