Re: Generate a Google Translate API token through the Socks5 proxy using gtoken.py

2021-07-30 Thread Peter Otten

On 29/07/2021 17:43, Dennis Lee Bieber wrote:

On Thu, 29 Jul 2021 15:45:26 +0200, Peter Otten <__pete...@web.de>
declaimed the following:


On 28/07/2021 18:40, Dennis Lee Bieber wrote:

On Wed, 28 Jul 2021 09:04:40 +0200, Peter Otten <__pete...@web.de>
declaimed the following:



Perhaps it has something to do with the X-No-Archive flag set by Dennis?


According to my properties page in Agent, I've turned that off except
if the message I'm replying to has it set.


I'm yet to see an archived post by you -- maybe that setting is
overridden somewhere.


And naturally, once I found the legacy (per persona) custom setting, I
failed to edit the main persona. Hopefully this time it's set...


https://mail.python.org/pipermail/python-list/2021-July/902975.html

You are now officially archived ;)

--
https://mail.python.org/mailman/listinfo/python-list


Re: Defining a Python enum in a C extension - am I doing this right?

2021-07-30 Thread Serhiy Storchaka
23.07.21 11:20, Bartosz Golaszewski пише:
> I'm working on a Python C extension and I would like to expose a
> custom enum (as in: a class inheriting from enum.Enum) that would be
> entirely defined in C.

I think that it would be much easier to define it in Python, and then
either import a Python module in your C code, or exec a Python code as a
string.

-- 
https://mail.python.org/mailman/listinfo/python-list


RE: Defining a Python enum in a C extension - am I doing this right?

2021-07-30 Thread Schachner, Joseph
Instead of struggling to define an enum  in C that can be read in Python - I'm 
assuming you can pass strings back and forth - why not just print whatever you 
need to give to Python into a string (or maybe 2 strings) and send it to Python 
as string?   Python is a dynamic language, it can quickly build an enum  type 
from one string and instantiate enums of that type from the other string.  

In short, if you have problems creating an enum in C and passing it to Python, 
give the problems to Python! Let it create the enum.

--- Joseph S.


Teledyne Confidential; Commercially Sensitive Business Data

-Original Message-
From: Serhiy Storchaka  
Sent: Friday, July 30, 2021 4:22 AM
To: python-list@python.org
Subject: Re: Defining a Python enum in a C extension - am I doing this right?

23.07.21 11:20, Bartosz Golaszewski пише:
> I'm working on a Python C extension and I would like to expose a 
> custom enum (as in: a class inheriting from enum.Enum) that would be 
> entirely defined in C.

I think that it would be much easier to define it in Python, and then either 
import a Python module in your C code, or exec a Python code as a string.

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Generate a Google Translate API token through the Socks5 proxy using gtoken.py

2021-07-30 Thread Dennis Lee Bieber
On Fri, 30 Jul 2021 13:17:50 +0200, Peter Otten <__pete...@web.de>
declaimed the following:

>
>https://mail.python.org/pipermail/python-list/2021-July/902975.html
>
>You are now officially archived ;)

Pity the choice was the boolean "X-No-Archive"... Consensus
implementation of an "X-Expire-After: " would have been friendlier
(Google Groups USED to expire X-No-Archive posts after a week, instead of
the current practice of: post says no-archive, delete immediately).


-- 
Wulfraed Dennis Lee Bieber AF6VN
wlfr...@ix.netcom.comhttp://wlfraed.microdiversity.freeddns.org/

-- 
https://mail.python.org/mailman/listinfo/python-list


Importing modules with arguments

2021-07-30 Thread Charles Smith
I have found myself wanting to import module and provide arguments to them. 
There's two main reason I could think of for this. First is to prevent a 
circular import, though most of circular imports can be prevented by changing 
the design. The second reason is to invert dependencies between two modules. It 
occurred to me when using libraries like FastAPI or Flask that it would be 
nicer to use and leaner if instead of:
1. Import FastAPI Router or FastAPI object directly
2. Create a Router
3. Use the route decorators

We could simply import a module with importlib and provide the router itself. 
You can then keep all the FastAPI related code inside its module and only have 
clean list of endpoints. Now this is actually doable right now, here's the 
snippet: https://gist.github.com/BinarSkugga/c281cbbe36e7f11bc0fd143ea1bb4dd4

Disclaimer: I have no idea what are the implication of this but I'd like to 
have it as a feature instead of this hack.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Importing modules with arguments

2021-07-30 Thread Chris Angelico
On Sat, Jul 31, 2021 at 3:48 AM Charles Smith  wrote:
>
> I have found myself wanting to import module and provide arguments to them. 
> There's two main reason I could think of for this. First is to prevent a 
> circular import, though most of circular imports can be prevented by changing 
> the design. The second reason is to invert dependencies between two modules. 
> It occurred to me when using libraries like FastAPI or Flask that it would be 
> nicer to use and leaner if instead of:
> 1. Import FastAPI Router or FastAPI object directly
> 2. Create a Router
> 3. Use the route decorators
>
> We could simply import a module with importlib and provide the router itself. 
> You can then keep all the FastAPI related code inside its module and only 
> have clean list of endpoints. Now this is actually doable right now, here's 
> the snippet: 
> https://gist.github.com/BinarSkugga/c281cbbe36e7f11bc0fd143ea1bb4dd4
>
> Disclaimer: I have no idea what are the implication of this but I'd like to 
> have it as a feature instead of this hack.
>

One problem here is that imports are cached. If module #1 says "import
flask", Python runs the module and gives back the result; if module #2
subsequently says "import flask", Python returns the exact same module
from the cache. That won't work well with parameterization.

I would recommend either:

1) Import a class from the module, then instantiate; or
2) Import the module, then make a change to its globals.

The first one allows different modules to have different parameters;
the second would have different parameters overwrite each other. (And
it would be very clear that it's going to do so.)

The idiom "from flask import Flask; flask = Flask()" is a bit clunky,
but it's probably the best you have for adding parameters. (In this
specific case, "app = Flask()", which is more common, but same
difference.) I can't really imagine shortening it very much; a syntax
like "import flask()" would be confusing, and every other syntax I can
think of will be only marginally better than the standard idiom.

There is one important situation where you can't just import the whole
module and then do stuff, and that's choosing to import *less* than
the full module. For that use-case, it kinda has to be a package, but
then you should be able to do something like:

package/__init__.py
# all the basic stuff in this file

package/expensive1.py
package/expensive2.py
package/expensive3.py
# different parts

package/all.py
from . import expensive1, expensive2, expensive3

Then you can say something like:

import package.expensive2

and it'll only get some part of the package. It's a bit unideal in
that the namespace has to reflect this, but with careful use of
__getattr__, you could conceal those details (at the cost of even more
complexity). On the upside, though, the parameterization doesn't have
to break anything - if module 1 imports one part of the package, and
module 2 imports another part, both parts will coexist nicely.

ChrisA
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Importing modules with arguments

2021-07-30 Thread Charles Smith
First off, thanks for the answer. I don't see the cached module as a problem 
here. If you provide arguments to a module, the goal is "most likely" to 
alter/parameterize the behavior of the first import. Now, I agree that behavior 
becomes unpredictable because passing different parameters on subsequent 
imports won't change the behavior of the imported module . One thing that could 
be done is to memoize those imports based on the parameters (this is a huge 
change to how imports works so its a bit yikes). Another solution would be to 
simply not cache parameterized imports. You sacrifice performance for added 
flexibility which I think is fair. I do however agree about partial imports. It 
would be rather complex to properly pass the context but its certainly doable.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Importing modules with arguments

2021-07-30 Thread Chris Angelico
On Sat, Jul 31, 2021 at 5:11 AM Charles Smith  wrote:
>
> First off, thanks for the answer. I don't see the cached module as a problem 
> here. If you provide arguments to a module, the goal is "most likely" to 
> alter/parameterize the behavior of the first import. Now, I agree that 
> behavior becomes unpredictable because passing different parameters on 
> subsequent imports won't change the behavior of the imported module .
>

The trouble is that if any other module has already imported the one
you're trying to parameterize, then your code won't know that the
parameters haven't been applied. It's action at a distance.

> One thing that could be done is to memoize those imports based on the 
> parameters (this is a huge change to how imports works so its a bit yikes).

That's functionally equivalent to importing a class and then
instantiating, but with an automated cache. Could be interesting, but
belongs inside the module, not as a language mechanic, IMO.

> Another solution would be to simply not cache parameterized imports. You 
> sacrifice performance for added flexibility which I think is fair.

And that's functionally equivalent to importing a class and then
instantiating, *without* the automated cache. :)

> I do however agree about partial imports. It would be rather complex to 
> properly pass the context but its certainly doable.
>

Yeah.

So here's a possibility. Craft a module-level __getattr__ function
that does the caching behaviour you want. Then you can "from
modulename import Thing", where the precise name you want is the
selection of parameter. The __getattr__ function can also set it as an
intrinsic attribute (thus offering high performance caching - it'll
bypass __getattr_ the second time). Other than that, though, there's
not really a lot of parameterization that would make sense as part of
the import (if you need to say something like "import random;
random.seed(12345)", that's not really going to fit into the import
statement).

ChrisA
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: [Errno 2] No such file or directory:

2021-07-30 Thread Sean DiZazzo
On Thursday, July 29, 2021 at 7:42:58 AM UTC-7, joseph pareti wrote:
> indeed. There are better options than the one I attempted. Thanks for the 
> advice 
> 
> Am Mi., 28. Juli 2021 um 18:19 Uhr schrieb Chris Angelico  >:
> > On Thu, Jul 29, 2021 at 2:10 AM joseph pareti 
> > wrote: 
> > > 
> > > The following code fails as shown in the title: 
> > > 
> > > 
> > > 
> > > 
> > > 
> > > 
> > > *import subprocesscmd = 'ls -l 
> > > 
> > /media/joepareti54/Elements/x/finance-2020/AI/Listen_attend_spell/VCTK-Corpus/wav48
> >  
> > > | awk "{print $9 }"'process = subprocess.Popen([cmd],
> > > stdout=subprocess.PIPE, stderr=subprocess.PIPE)stdout, stderr = 
> > > process.communicate()print('stdout ',stdout)print('stderr ',stderr)* 
> > > 
> > >  
> > > 
> > > Traceback (most recent call last): 
> > > File "PreProcess_1a.py", line 3, in  
> > > process = subprocess.Popen([cmd], stdout=subprocess.PIPE, 
> > > stderr=subprocess.PIPE) 
> > > File "/home/joepareti54/anaconda3/lib/python3.8/subprocess.py", line 
> > 854, 
> > > in __init__ 
> > > self._execute_child(args, executable, preexec_fn, close_fds, 
> > > File "/home/joepareti54/anaconda3/lib/python3.8/subprocess.py", line 
> > > 1702, in _execute_child 
> > > raise child_exception_type(errno_num, err_msg, err_filename) 
> > > FileNotFoundError: [Errno 2] No such file or directory: 'ls -l 
> > > 
> > /media/joepareti54/Elements/x/finance-2020/AI/Listen_attend_spell/VCTK-Corpus/wav48
> >  
> > > | awk "{print $9 
> > > 
> >
> > First off, you'll want to post code in a way that keeps the 
> > formatting, otherwise it becomes very hard to read. 
> > 
> > But the immediate problem here is that Popen takes an array of command 
> > arguments, NOT a shell command line. You cannot invoke ls and pipe it 
> > into awk this way. 
> > 
> > Don't think like a shell script. Python has very good 
> > directory-listing functionality, and you will very very seldom need to 
> > shell out to pipelines. Figure out what you actually need to learn 
> > from the directory listing and get that information directly, rather 
> > than trying to use two external commands and text parsing. It's far 
> > FAR easier, cleaner, and safer that way. 
> > 
> > ChrisA
> > -- 
> > https://mail.python.org/mailman/listinfo/python-list
> > 
> 
> 
> -- 
> Regards, 
> Joseph Pareti - Artificial Intelligence consultant 
> Joseph Pareti's AI Consulting Services 
> https://www.joepareti54-ai.com/ 
> cell +49 1520 1600 209 
> cell +39 339 797 0644

I prefer LOLCODE for these kinds of tasks.

HAI 1.2
I HAS A VAR ITZ MAH_DIRECTORY
GIMMEH MAH_DIRECTORY

CAN HAS STDIO?
BOTH SAEM MAH_DIRECTORY AN 
"/media/joepareti54/Elements/x/finance-2020/AI/Listen_attend_spell/VCTK-Corpus/wav48",
 O RLY?
  YA RLY, VISIBLE "FILEZ GO HERE!"
  NO WAI, VISIBLE "WTF IZ THAT?"
OIC

KTHXBYE
-- 
https://mail.python.org/mailman/listinfo/python-list