Is there a difference between the following 2 ways to launch a console-less
script under Windows?
python
Any recommendations on a library providing a simple interface to Github for
basic push/pull type of actions? I know there's a native GitHub RESTful API but
wondering if anyone has placed a friendly Python wrapper on top of that
interface? PyGithub supports a rich set of actions, but doesn't appe
Is the cryptography package still considered the "best" cross-platform package
for encrypting sensitive data being stored in files on disk. Use case: JSON
data files containing potentially confidential/PII data using something along
the lines of AES256 encryption. Goal is to encrypt data in memo
Thanks Paul and Dan.
@Paul: Yes, it *IS* a bit confusing . Your pip explanation hit the spot.
@Dan: Yes, symlinks would be a good work around.
Malcolm
--
https://mail.python.org/mailman/listinfo/python-list
I'm jumping between Linux, Mac and Windows environments. On Linux and Mac we
can invoke Python via python3 but on Windows it appears that only python works.
Interestingly, Windows supports both pip and pip3 flavors. Am I missing
something? And yes, I know I can manually create a python3 alias by
Hi Dave,
> I agree that a traditional INI file is the easiest way, especially since
> Python supports them. So if I understand you, your apps look like this:
Yes with the following nuance for our application sized scripts that require
multiple configuration files. In this latter case, we place
Hi Dave,
> The plan for an app that I'm doing was to use SQLite for data and to hold the
> preference settings as some apps do. The plan was changed last week to allow
> the user to select the location of the data files (SQLite) rather than
> putting it where the OS would dictate. Ok with tha
Python Cookbook; highly recommended.
Malcolm
--
https://mail.python.org/mailman/listinfo/python-list
You may need to update your ODBC driver from version 13 to 17.x.
Malcolm
--
https://mail.python.org/mailman/listinfo/python-list
> I am exactly in the "pretty advanced usage": I want to create a zip that
> embed numpy. In this case, I have to bundle the C extension. How can I do
> that?
1. PyInstaller
2. PyOxide (new technology, may or may not support Numpy)
Let us know how you make out.
Malcolm
--
https://mail.python
> 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?
Thanks,
Malcolm
--
https://mail.python.org/mailman/listinfo/python-list
> From: Chris Angelico
> Are you doing this in cmd.exe, powershell, bash, or some other shell?
Same result via cmd.exe and PowerShell (ps1).
> There are a LOT of ways that the Windows path can fail to pick up the correct
> 'pip'. Normally activating a venv should let you use "pip" to mean the r
> From: Ed Leafe
> StackOverflow:
> https://stackoverflow.com/questions/25584276/how-to-disable-site-enable-user-site-for-an-environment
Thanks Ed! My takeaway from the above article and our path going forward is to
explictly force ENABLE_USER_SITE to false via Python's "-s" switch.
Malcolm
--
> you must be picking up pip from a different python install (or virtualenv)
> than you are picking up python.
> Check your %PATH%
That was our first guess. Only one version of Python installed on the system
(we install on an empty, freshly serviced pack Windows VM). Only one version of
python*
Any suggestions on how one can force the "python -m site" ENABLE_USER_SITE
value to false?
Is it possible to globally force this setting - across all users - when
installing a system wide version of Python ... or via a command line option
when starting a Python session?
Motivation: When ENABLE
64-bit Python 3.6.8 running on Windows with a virtual environment activated.
"pip -v" reports 19.0.3
"python -m pip" reports 19.1.1
Is this behavior by design or a bug?
My takeaway is that its better to run "python -m pip ..." vs "pip ..." when
running pip related tasks.
Thoughts?
Malcolm
--
I have a collection of command line scripts that share a collection of common
modules. This code collection is for internal use and will run under a single
version of Python 3.6+ and a single OS. My understanding of best practice is to
organize this collection of Python files into a folder struc
> This has nothing to do with Python does it? Isn't Python is just writing to
> stdout and those write calls are blocking due because the terminal emulator
> has stopped reading the other end of the
> pipe/pty/queue/buffer/whatever-it's-called-in-windows?
You're right. But I wasn't sure. I know
Eryk,
> Another common culprit is quick-edit mode, in which case a stray mouse click
> can select text, even just a single character. The console pauses while text
> is selected.
MYSTERY SOLVED !! THANK YOU !!
Apparently, while mouse clicking between windows, I was inadvertently selecting
a c
I'm running some Python 3.6 scripts at the Windows 10/Windows Server 2016
console. In my every day workflow, I seem to be accidentally sending Ctrl+S
keystrokes to some of console sessions, pausing my running scripts until I send
another corresponding Ctrl+S to un-pause the affected scripts. My
Use case: I have a Python manager script that monitors several conditions (not
just time based schedules) that needs to launch Python worker scripts to
respond to the conditions it detects. Several of these worker scripts may end
up running in parallel. There are no dependencies between individu
Looking for best practice technique for converting Windows style paths to Linux
paths. Is there an os function or pathlib method that I'm missing or is it some
combination of replacing Windows path separators with Linux path separators
plus some other platform specific logic?
Thank you,
Malcolm
[Reformatted as original post got mangled]
Looking for advice on the best way to remove unused modules from a Python
virtual environment. My setup is Python 3.6.6 running on macOS although I
believe my use case is OS independent.
Background: Long running project that, over the course of time, p
Looking for advice on the best way to remove unused modules from a
Python virtual environment. My setup is Python 3.6.6 running on macOS
although I believe my use case is OS independent.
Background: Long running project that, over the course of time, pip installed
modules that are no longer used b
Any recommendations on normalizing path strings in cross platform
(Windows, Linux, macOS) for unit tests?
Our goal is to normalize path strings to use forward slash separators so
that we can consistently reference path strings in our unit tests in a
cross platform way.
Example: Under Windows we hav
I noticed that there's a rather big gap between the latest version of
SQLite and the version of SQLite that ships with Python 3.6/3.7.
Is there best practice advice for upgrading the SQLlite C library that
ships with Python ... without causing havoc and mayhem on my system?
Options
Don't do it - th
I have a class method that adds additional context to many of the
class's log messages. Rather than calling, for example, logger.info(
'message ...' ) I would like to call my_object.log( 'message ...' ) so
that this additional context is managed in a single place. I'm actually
doing that and its w
Curious to learn what Python related git pre-commit hooks people are
using? What hooks have you found useful and which hooks have you tried
and abandoned? Appreciate any suggestions for those new to this process.
Background: Window, macOS, and Linux dev environments, PyCharm professional
edition I
Curious to hear if any of you are running Python scripts/apps on MS
Azure cloud services? What services are you using and what has your
experience been? Advice?
Background: Customer migrating to Azure. I'm trying to get ahead of the curve
regarding how Python-friendly the Azure platform is.
Thanks
Is there a technique that would allow a script to verify its
requirements.txt file before it runs? Use case: To detect unexpected
changes to a script's runtime environment. Does the pip module expose
any methods for this type of task?
Thank you,
Malcolm
--
https://mail.python.org/mailman/listinfo/
I'm using the Python logging module and looking for a way to include a
method's class name when using %(funcName). Is this possible? When you
have several related classes, just getting the function (method) name is
not enough information to provide context on the code being executed.
I'm outputting
Use case: Want to prevent 2+ instances of a script from running ... ideally in
a cross platform manner. I've been researching this topic and am surprised how
complicated this capability appears to be and how the diverse the solution set
is. I've seen solutions ranging from using directories, named
Use case: Want to prevent 2+ instances of a script from running ...
ideally in a cross platform manner. I've been researching this topic and
am surprised how complicated this capability appears to be and how the
diverse the solution set is. I've seen solutions ranging from using
directories, named
Thanks for the replies! I'm going to investigate the use of python-gnupg [1]
which is a Python wrapper for the GPG command line utility. This library is
based on gpg.py written by Andrew Kuchling. I'm all ears if f anyone has any
alternative recommendations or python-gnupg tips to share. BTW:
Is there a benefit to using one of these techniques over the other?
Is one approach more Pythonic and preferred over the other for
style reasons?
message = message.encode('UTF-8')
message = bytes(message, 'UTF-8')
Thank you,
Malcolm
--
https://mail.python.org/mailman/listinfo/python-list
I have use case where I need to distribute binary files to customers and
want to provide a way for our customers to verify the
"integrity/lineage" (I know there's a better description, but can't
think of it) of these files, eg. to give them the confidence that the
files in question are from me and
Thanks to everyone who contributed to this thread. Great feedback and
suggestions! - Malcolm
--
https://mail.python.org/mailman/listinfo/python-list
> You might try:
> from getopt import getopt
> or the (apparently newer):
> from optparse import OptionParser
Thanks Mike. My question was trying to make a distinction between Python
options (flags that precede the script or module name) and arguments (the
script specific values passed on the co
> If you run the script directly, by entering >script.py or clicking a script
> icon or name in File Explorer, it runs python without python options *other
> than those specified in environmental variables*.
Understood. I thought there might have been a way to pass Python option values
via a si
When you run a script via "python3 script.py" you can include command
line options like -b, -B, -O, -OO, etc between the "python3" interpreter
reference and the script.py file, eg. "python3 -b -B -O -OO script.py".
When you create a script that is executable directly, eg. script.py with
execution b
Looking for feedback on anyone who's using a cloud based
monitoring/logging service with Python's standard lib logging module,
eg. services such as Datadog, Loggly, Papertrailapp, Scalyr, LogDNA,
Logz.io, Logentries, Loggr, Logstats?
Would appreciate hearing your experience, pros, cons,
recommendat
We're using virtual environments with Python 3.6. Since all our pip
installed modules are in our environment's local site-packages folder,
is the distribution of a virtual environment as simple as recursively
zipping the environment's root folder and distributing that archive to
another machine run
> Perhaps it doesn't need to be said, but just to be sure: don't use eval if
> you don't trust the people writing the configuration file. They can do nearly
> unlimited damage to your environment. They are writing code that you are
> running.
Of course! Script and config file are running in a
Looking for your suggestions on best practice techniques for managing
secrets used by Python daemon scripts. Use case is Windows scripts
running as NT Services, but interested in Linux options as well.
Here's what we're considering
1. Storing secrets in environment vars
2. Storing secrets in confi
My original post reformatted for text mode:
Looking for advice on how to expand f-string literal strings whose values I'm
reading from a configuration file vs hard coding into
my script as statements. I'm using f-strings as a very simple template language.
I'm currently using the following tech
Looking for advice on how to expand f-string literal strings whose
values I'm reading from a configuration file vs hard coding into
my script as statements. I'm using f-strings as a very simple
template language.
I'm currently using the following technique to expand these f-strings.
Is there a bett
Thank you Peter and Jussi - both your solutions were very helpful!
Malcolm
--
https://mail.python.org/mailman/listinfo/python-list
Wondering if there's a standard lib version of something like
enumerate() that takes a max count value?
Use case: When you want to enumerate through an iterable, but want to
limit the number of iterations without introducing if-condition-break
blocks in code.
Something like:
for counter, key in en
Looking for best practice tips on how to size thread/process pools or
max workers with the concurrent futures module. Are there specific
heuristics that can be applied or is this more a manual tuning process
based on the run time behavior of a script and the nuances of one's
environment? Are there
I have a bunch of pickled dicts I would like to merge. I only want to
merge unique keys but I want to track the keys that are duplicated
across dicts. Is there a newer dict-like data structure that is fine
tuned to that use case?
Short of an optimized data structure, my plan is to convert dict keys
Another endorsement for Webfaction.
--
https://mail.python.org/mailman/listinfo/python-list
Looking for a quick way to calculate lines of code/comments in a
collection of Python scripts. This isn't a LOC per day per developer
type analysis - I'm looking for a metric to quickly judge the complexity
of a set of scripts I'm inheriting.
Thank you,
Malcolm
--
https://mail.python.org/mailman/
Hi Paul,
> Just one further note, which may or may not be obvious. If your application
> uses external dependencies from PyPI, you can bundle them with your
> application using pip's --target option ...
Cool stuff! To your question: None of what you've shared has been
obvious to me :)
Packagi
Oscar/MRAB,
> You could put something between the file and the reader ...
Thank you both for your suggestions ... brilliant! You guys helped me
solve my problem and gave me an excellent strategy for future scenarios.
Malcolm
--
https://mail.python.org/mailman/listinfo/python-list
Looking for ideas on how I can obtain the raw line of text read by a
CSVDictReader. I've reviewed the CSV DictReader documentation and there
are no public attributes that expose this type of data.
My use case is reporting malformed lines detected when my code
validates the dict of data returned by
Hi Paul,
WOW!:)
I really appreciate the detailed response. You answered all my
questions. I'm looking forward to testing out your pylaunch wrapper.
Thank you very much!
Malcolm
--
https://mail.python.org/mailman/listinfo/python-list
Looking for tips or edge case gotchas associated with using Python 3.5's
new zipapp feature. For those of you wondering what this feature is, see
the end of this post for a brief background [1].
Two questions in particular:
1. Are there any issues with deploying scripts that sit in sub-
folder
Thanks for your suggestions Chris and Terry.
The answer I was looking for is the modulefinder module which is part of
the standard lib. Works like a charm!
Quote: This module provides a ModuleFinder class that can be used to
determine the set of modules imported by a script. modulefinder.py can
a
Looking for suggestions on how, given a main script, discover all the
non-standard library modules imported across all modules, eg. the
modules that other modules import, etc. I'm not looking to discover
dynamic imports or other edge cases, just the list modules loaded via
"import " and "from impo
Ned and Random832,
Ned: Thank you - your example answered my question.
Random832: Thank you for the reminder about "from import
" still importing the module. Yes, I had forgotten that behavior.
Best,
Malcolm
--
https://mail.python.org/mailman/listinfo/python-list
Python 3.5: Is there a way to dynamically import specific names from a
module vs importing the full module?
By dynamic I mean via some form of importlib machinery, eg. I'm looking
for the dynamic "from import " equivalent of "import
"'s importlib.import_module.
Thank you,
Malcolm
--
https://mai
Background: I'm building a rules engine for transforming rows of data being
returned by csv DictReader, eg. each row of data is a dict of column name to
value mappings. My rules are a list of rule objects whose attributes get
referenced by rule specific methods. Each rule has an associated meth
Wow!!! A huge thank you to all who replied to this thread!
Chris: You gave me some ideas I will apply in the future.
MRAB: Thanks for exposing me to the extended attributes of the UnicodeError
object (e.start, e.end, e.object).
Mike: Cool example! I like how _cleanlines() recursively calls itse
Hi Chris,
Thanks for your suggestions. I would like to capture the specific bad
codes *before* they get replaced. So if a line of text has 10 bad codes
(each one raising UnicodeError), I would like to track each exception's
bad code but still return a valid decode line when finished.
My goal is
I'm processing a lot of dirty CSV files and would like to track the bad
codes that are raising UnicodeErrors. I'm struggling how to figure out
what the exact codes are so I can track them, them remove them, and then
repeat the decoding process for the current line until the line has been
fully deco
> You could use win_unicode_console enabled in sitecustomize or usercustomize.
> https://pypi.python.org/pypi/win_unicode_console
The pypi link you shared has an excellent summary of the issues
associated when working Unicode from the Windows terminal.
Thank you Eryk.
Malcolm
--
https://mail.py
Chris,
> Don't forget that the print function can simply be shadowed.
I did forget! Another excellent option. Thank you!
Malcolm
--
https://mail.python.org/mailman/listinfo/python-list
Thank you Random832 and Peter - excellent ideas.
My use case was diagnostic output being (temporarily) output to stdout
via debug related print statements. The output is for debugging only and
not meant for production. I was looking for a solution that would allow
me to output to the console with
Looking for a way to use the Python 3 print() function with encoding and
errors parameters.
Are there any concerns with closing and re-opening sys.stdout so
sys.stdout has a specific encoding and errors behavior? Would this break
other standard libraries that depend on sys.stdout being configured
Thank you Laurent!
- Original message -
From: Laurent Pointal
With __name__ you will have one logger per source file (module), with
corresponding filtering possibilities, and organized hierarchically as
are
packages (logging use . to built its loggers hierarchy).
Without __name__, y
Hi Eryk,
Awesome! Thank you very much for your detailed answer!!
Malcolm
Linux has the O_TMPFILE open() flag [1]. This creates an anonymous file
that gets automatically deleted when the last open file descriptor is
closed. If the file isn't opened O_EXCL, then you can make it permanent
by linki
Can someone share their OS specific experience in working with tempfile
generated temp files under these conditions?
1. Script killed by another process
2. Interpreter crashes
3. Server crashes (sudden loss of power)
4. Other application termination conditions ???
I'm curious which scenarios re
I've read that best practice for logging is to place the following line
at the top of all modules:
logger = getLogger(__name__)
I'm curious why the following technique wouldn't be a better choice:
logger = getLogger()
Are there scenarios that favor one style over another?
Thank you,
Malco
Hi Jussi,
You answered my questions - thank you!
Malcolm
> 1. The signature for glob.glob() is "glob.glob(pathname, *,
>recursive=False)". What is the meaning of the 2nd parameter listed
>with an asterisk?
It's not a parameter. It's special syntax to indicate that the remaining
paramete
In reading Python 3.5.1's glob.glob documentation[1] I'm puzzled by the
following:
1. The signature for glob.glob() is "glob.glob(pathname, *,
recursive=False)". What is the meaning of the 2nd parameter listed
with an asterisk?
2. Is there a technique for using glob.glob() to recognize fi
Hi Steven and Peter,
Steven: Interestingly (oddly???) enough, the output captured by hooking
the cgitb handler on my system appears to be shorter than the default
cgitb output. You can see this yourself via this tiny script:
import cgitb
cgitb.enable(format='text')
x = 1/0
The solution I came up
Is there a way to capture cgitb's extensive output in an except clause
so that cgitb's detailed traceback output can be logged *and* the except
section can handle the exception so the script can continue running?
My read of the cgitb documentation leads me to believe that the only way
I can get c
Hi Peter,
> Fine! Then you can avoid the evil hack I came up with many moons ago:
> https://mail.python.org/pipermail/python-list/2010-March/570941.html
Evil? Damn evil! Love it!
Thank you,
Malcolm
--
https://mail.python.org/mailman/listinfo/python-list
Hi Terry,
>> Is there a technique for accessing a function's *CALLER* module name,
>> function/method name and line number so that this information can be
> Look in the inspect module for the inspect stack function. Note that
> when you call the function, it needs to look 2 levels up.
Perfect!
Is there a technique for accessing a function's *CALLER* module name,
function/method name and line number so that this information can be
passed to a logging library's logger? I have a routine that detects an
error condition, but I want to report the error's context relative to
the caller, not the
Hi Michael,
> Out[3]: 'HELLO'
> In [4]: g = str.upper
> In [5]: g(s)
> Out[5]: 'HELLO'
That's perfect! My mistake was trying to use the method returned by
''.upper vs. str.upper.
Thank you,
Malcolm
--
https://mail.python.org/mailman/listinfo/python-list
I know I can do the following:
>>> s = 'lower'
>>> getattr(s, 'upper')()
'LOWER'
But how could I do the same if I had the method 'address' (better
name???) vs. method name?
>>> upper_method = s.upper
How do I combine this upper_method with string s to execute the method
and return 'LOWER'?
Hi Tim,
> I think that what you're looking for is a topological sort
BINGO! That's *exactly* what I was searching for.
Thank you very much,
Malcolm
--
https://mail.python.org/mailman/listinfo/python-list
We're working on a DSL (domain specific language) that we translate into
a list of tokenized expressions. My challenge is to figure out how to
sequence evaluation of these expressions so that we evaluate these
expressions in the proper order given that expressions have dependencies
on other express
> Heh, great question, and I'm curious too! But one place to get a bit more
> info is the standard library.
>
> rosuav@sikorsky:~/cpython/Lib$ find -name \*.py|xargs ls -lS|head
> -rw-r--r-- 1 rosuav rosuav 624122 Jul 17 17:38 ./pydoc_data/topics.py
Brilliant! :)
Thanks Chris!
Malcolm
--
http
We're writing a DSL parser that generates Python code. While the size of
our generated code will be small (< 32K), I wanted to re-assure the rest
of our team that there are no reasonable code size boundaries that we
need to be concerned about. I've searched for Python documentation that
covers max
Thank you Chris and Peter.
The source file we're generating has one main function (go) with some
supporting functions and classes as well. Will there be any problems
referencing additional functions or classes defined in the source that
gets passed to exec ... as long as references to those functi
We're designing a server application that parses a custom DSL (domain
specific language) source file, generates a Python module with the
associated logic, and runs the associated code. Since this is a server
application, we need to reload the module after each regeneration. Is
this process is simpl
Peter,
> I think it doesn't matter whether you type in text, or insert it with Ctrl+V
> or the middle mouse button. The validatecommand handler is always triggered.
> I suspect achieving the same effect with Button/KeyPress handlers would
> require significantly more work.
Thank you!
Malcolm
-
Andrea,
What type of result do you get trying port 993 ?
Malcolm
--
http://mail.python.org/mailman/listinfo/python-list
Tim,
> The underscore is a valid variable-name, idiomatically used for "I don't care
> about this", often seen in places like tuple assignment:
The underscore is also used as an alias for gettext.gettext or
gettext.ugettext so you may want to use another variable-name.
Malcolm
--
http://mail.p
Looking for advice on what Python license and copyright text to
include and where to include it when selling a commercial
(Windows based) Python based application.
By license text and copyrights I am refering to the text on this
page:
PYTHON SOFTWARE FOUNDATION LICENSE VERSION 2
http://www.python
Hi Gabriel,
> in Python 3.0 keys() behaves as iterkeys() in previous versions, so the above
> code is supposed to be written in Python 2.x)
I understand. Thank you.
> note that dict comprehensions require Python 3.0
I'm relieved to know that I didn't miss that feature in my reading of
Python's
Hi Roger,
By very large dictionary, I mean about 25M items per dictionary. Each
item is a simple integer whose value will never exceed 2^15.
I populate these dictionaries by parsing very large ASCII text files
containing detailed manufacturing events. From each line in my log file
I construct one
My two favorites:
- Core Python Programming by Chun
- Learning Python by Lutz
Malcolm
--
http://mail.python.org/mailman/listinfo/python-list
Is there any consensus on what "from __future__ import" options
developers should be using in their Python 2.5.2 applications?
Is there a consolidated list of "from __future__ import" options to
choose from?
Thank you,
Malcolm
--
http://mail.python.org/mailman/listinfo/python-list
The locale module provides the ability to format dates, currency and
numbers according to a specific locale.
Is there a corresponding module for parsing locale's output to convert
locale formatted dates, currency, and numbers back to their native data
types on the basis of a specified locale?
In
I'm looking for tips on how to load balance running multiple Python
applications in multi-CPU environments. My understanding is that Python
applications and their threads are limited to a specific CPU.
Background: I have a Python utility that processes email messages. I
suspect there's a lot of id
E-Lo,
PalmPython
http://c2.com/cgi/wiki?PalmPython
I have no experience with Python for Palm OS's. This is just a reference
from my personal notes.
Malcolm
--
http://mail.python.org/mailman/listinfo/python-list
Stefan,
> My personal experience with wxPython has its ups and downs. Specifically when
> it comes to crashes, I wouldn't bet my life on it. (but then, the OP
I'm new to Python and getting ready to build a small client based
application intended to run on Windows and Linux. I was planning on
usi
1 - 100 of 103 matches
Mail list logo