Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
IAmKale
Jun 7, 2007

やらないか

Fun Shoe

NtotheTC posted:

As an aside, what syntax is this? I've not seen this before in Python.
That's Python type annotations, available since 3.5. It doesn't activate strong typing or anything, it's just a way to add in expected inputs and outputs to method definitions. The part after -> is the method's return value type.

Adbot
ADBOT LOVES YOU

IAmKale
Jun 7, 2007

やらないか

Fun Shoe

xgalaxy posted:

Apologies if this has been asked in here before.

I'm using Google Cloud SDK (Note: not App Engine SDK although they are very similar).
In additional this I am using google-cloud-bigquery, google-cloud-pubsub, and some other google things.

It appears none of these things work properly with pylint. I get unable to import 'google.cloud' stuff everywhere I'm trying to use this stuff.
If I bring up a repl and import from google.cloud it works fine and of course running Google's app engine local dev server it runs fine.

Why is this such a mess?
I have the exact same setup (using pylint on a GCP application) but I couldn't remember ever having this issue. It looks like I worked around it by adding this line to the project's pylintrc file:

code:
ignored-modules=google
Does that help?

IAmKale
Jun 7, 2007

やらないか

Fun Shoe

LochNessMonster posted:

I was wondering there was a more pythonic way of doing this:

List comprehensions are pretty pythonic. How about something like this?

code:
d1 = { "servertype" : ["name1", "name2"], "servertype2" : ["name3"] }
d2 = { "servertype" : ["extension1", "extension2"], "servertype2" : ["extension3"] }

some_list = []

for k, v in d1.items():
    if k in d2:
        some_list += ['{}{}'.format(x, y) for x in d1[k] for y in d2[k]]

# Returns ['name1extension1', 'name1extension2', 'name2extension1', 'name2extension2', 'name3extension3']
print(some_list)

IAmKale
Jun 7, 2007

やらないか

Fun Shoe

Eela6 posted:

IAmKale, I like your solution except for one thing: it doesn't duplicate the behavior of the original function in the case that a key in d1 is missing from d2. The original function will raise a KeyError, but yours will silently ignore that key.
Argh, busted. I got so caught up in fixing the example code that I assumed the mismatched keys were a typo :negative:

IAmKale
Jun 7, 2007

やらないか

Fun Shoe
I have a bit of a conundrum: how do I lint my code when my application's Python environment is contained in a Docker container?

I just spun up a new Django project and stumbled a bit when I realized that I don't know what environment path to point the linter to. This is preventing Flake8 from understanding that I have Django installed, and it's outputting typical linting issues like the E0401 one below:



I feel as though my only option is to maintain a virtual environment on my machine that I'll have to keep in sync with the dependencies running in the Docker image that's serving the actual application. Unless there's a better way?

IAmKale
Jun 7, 2007

やらないか

Fun Shoe

nonathlon posted:

What's a stable library for building a REST client?
The de facto choice these days is still Django Rest Framework for Django. Aside from that you could use leaner alternatives like Flask or Falcon but in the end you just might end up writing a lot of functionality that comes out of the box with DRF.

IAmKale
Jun 7, 2007

やらないか

Fun Shoe

Falcon2001 posted:

Ah, thanks! That totally fixes it.
You can also try setting PYTHONUNBUFFERED=0 as an environment variable when you execute your program. flush=True probably accomplishes the same thing, but with the environment variable you won't have to sprinkle the latter around your codebase.

Adbot
ADBOT LOVES YOU

IAmKale
Jun 7, 2007

やらないか

Fun Shoe

KICK BAMA KICK posted:

Python code:
if match := re.match(pattern, text):
    return match.group('foo')
Huh, I've been dabbling in Swift lately and they often make use of this pattern:
code:
if let needsToBeDefined = possiblyNil {
  // Do something with needsToBeDefined knowing that it's not null
}
This means that the walrus operator makes this same pattern possible in Python? Now I don't know what the fuss is all about, I think it's pretty useful...

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply