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
mr_package
Jun 13, 2000

Boris Galerkin posted:

Why not use tempfile for temp dirs? Iirc a tempfile.TemporaryDirectory should automatically clean itself up if you use it in a with statement, or you can call its cleanup() method explicitly.

And if it fails to do so at least it’s in the proper place in your OS for temp stuff and I’m assuming the OS will eventually remove those files/dirs when it does its housekeeping stuff.

Doesn't work for me right now (needs to be long-lived but cleared before next run and other code depends on it being not in OS temp dir) BUT definitely filing this away for future use because it looks so drat useful I'm sure I could use it other places. Being able to delete crap when the context manager closes is gonna be a useful thing and I never even considered there might be a module in the STL to do it.

mr_package fucked around with this message at 06:59 on Sep 9, 2019

Adbot
ADBOT LOVES YOU

Hollow Talk
Feb 2, 2014
Pytest has this as a built-in fixture as well, which is incredibly useful for testing.

Dominoes
Sep 20, 2007

Hey dudes. Would anyone be willing to help test if Python binaries I built work on similar systems? Looking for someone with a Ubuntu or Debian install to try this, and specify a Python version you don't have, >= 3.4. Looking for someone with Windows who doesn't have Python 3.7 installed to try it with Python 3.7 specified. Much appreciated.

Ie download and run the deb or MSI, navigate to an empty folder, run `pypackage install`, and enter an applicable version when asked. Run `pypackage python`, and see if the REPL shows the right version.

Dominoes fucked around with this message at 02:13 on Sep 10, 2019

Malcolm XML
Aug 8, 2009

I always knew it would end like this.

Dominoes posted:

Hey dudes. Would anyone be willing to help test if Python binaries I built work on similar systems? Looking for someone with a Ubuntu or Debian install to try this, and specify a Python version you don't have, >= 3.4. Looking for someone with Windows who doesn't have Python 3.7 installed to try it with Python 3.7 specified. Much appreciated.

Ie download and run the deb or MSI, navigate to an empty folder, run `pypackage install`, and enter an applicable version when asked. Run `pypackage python`, and see if the REPL shows the right version.

Install a vm and do it yourself dude

Dominoes
Sep 20, 2007

I don't get along well with Docker, and am looking for help on an open-source project. You might even be interested in using this later, if not now. What I'm specifically asking for help on is a proof-of-concept for getting official binaries hosted on python.org.

Dominoes fucked around with this message at 03:21 on Sep 10, 2019

CarForumPoster
Jun 26, 2013

⚡POWER⚡

Dominoes posted:

I don't get along well with Docker, and am looking for help on an open-source project. You might even be interested in using this later, if not now. What I'm specifically asking for help on is a proof-of-concept for getting official binaries hosted on python.org.

I’d like to suggest amazon workspaces free tier for windows. Takes about 4 seconds to set up.

Dominoes
Sep 20, 2007

CarForumPoster posted:

I’d like to suggest amazon workspaces free tier for windows. Takes about 4 seconds to set up.
Thanks; on it.

Fluue
Jan 2, 2008
What's the typical pattern for loading credentials from something like AWS SSM Parameter Store into an API wrapper while keeping class initialization lightweight? Is it typically

code:
# api.py
class MyAPIWrapper:
	def __init__(api_secret, api_user, **kwargs):
		# values passed in through caller making separate call to SSM parameter store
		... store the secret/other api auth setup in instance vars ...
and incur the call to AWS SSM every time you have to init the API wrapper? Or does it make more sense to do:

code:
# api.py
from myconfig import ssm_config_loader   # e.g. this returns

class MyAPIWrapper:
	def __init__(api_secret, api_user, **kwargs):
		... store the secret/other api auth setup in instance vars ...

api = MyAPIWrapper(**ssm_config_loader(api_key="my_api"))

Malcolm XML
Aug 8, 2009

I always knew it would end like this.

Dominoes posted:

I don't get along well with Docker, and am looking for help on an open-source project. You might even be interested in using this later, if not now. What I'm specifically asking for help on is a proof-of-concept for getting official binaries hosted on python.org.

https://developer.microsoft.com/en-us/windows/downloads/virtual-machines

free 60 day vms (just keep rebuilding it)

No docker needed. But a trivial dockerfile for this would be worth it since all you do is setup and d/l. And with microsoft's free CI/CD it'd run automatically which is a lot more reliable than asking idiot goons like myself to test

Malcolm XML
Aug 8, 2009

I always knew it would end like this.

Fluue posted:

What's the typical pattern for loading credentials from something like AWS SSM Parameter Store into an API wrapper while keeping class initialization lightweight? Is it typically

code:
# api.py
class MyAPIWrapper:
	def __init__(api_secret, api_user, **kwargs):
		# values passed in through caller making separate call to SSM parameter store
		... store the secret/other api auth setup in instance vars ...
and incur the call to AWS SSM every time you have to init the API wrapper? Or does it make more sense to do:

code:
# api.py
from myconfig import ssm_config_loader   # e.g. this returns

class MyAPIWrapper:
	def __init__(api_secret, api_user, **kwargs):
		... store the secret/other api auth setup in instance vars ...

api = MyAPIWrapper(**ssm_config_loader(api_key="my_api"))

The iron rule of dependency injection strongly suggests you do the latter. Your API wrapper should have no idea where it gets its keys.

crazysim
May 23, 2004
I AM SOOOOO GAY

Malcolm XML posted:

https://developer.microsoft.com/en-us/windows/downloads/virtual-machines

free 60 day vms (just keep rebuilding it)

No docker needed. But a trivial dockerfile for this would be worth it since all you do is setup and d/l. And with microsoft's free CI/CD it'd run automatically which is a lot more reliable than asking idiot goons like myself to test

GitHub Actions 2.0 is nice if you can get into the beta. You can get a full sample of it using Azure Pipelines (it's a fork) and forward port the setup to GitHub Actions 2.0 once it is released.

Dominoes
Sep 20, 2007

Malcolm XML posted:

https://developer.microsoft.com/en-us/windows/downloads/virtual-machines

free 60 day vms (just keep rebuilding it)

No docker needed. But a trivial dockerfile for this would be worth it since all you do is setup and d/l. And with microsoft's free CI/CD it'd run automatically which is a lot more reliable than asking idiot goons like myself to test
Sweet. I'm not sure why I've had such trouble with VMs before; tried Docker to help someone repro a bug and got nowhere, despite most people having no trouble. Also having flashbacks of an old Django tutorial that used Vagrant/Chef/Virtualbox. Looks like Windows Subsys for Linux now supports several distros, which may help too.

Boris Galerkin
Dec 17, 2011

I don't understand why I can't harass people online. Seriously, somebody please explain why I shouldn't be allowed to stalk others on social media!
What’s the reason you can’t just include functionality to download the official binaries and installing them into your custom ~/python-installs directory? Maybe you’ve said it already but I can’t find it in recent posts.

crazysim posted:

GitHub Actions 2.0 is nice if you can get into the beta. You can get a full sample of it using Azure Pipelines (it's a fork) and forward port the setup to GitHub Actions 2.0 once it is released.

I got into the Actions beta! Except I have no idea what to do with it. I really should take some time to look into CI/CD stuff again because it sounds pretty neat.

I got into the GitHub packages beta too. I hope they add the ability to host python packages there too but I think right now it’s just js stuff.

Boris Galerkin fucked around with this message at 09:19 on Sep 10, 2019

Dominoes
Sep 20, 2007

Boris Galerkin posted:

What’s the reason you can’t just include functionality to download the official binaries and installing them into your custom ~/python-installs directory? Maybe you’ve said it already but I can’t find it in recent posts.
There are no official binaries that don't tie into the system. This may change soon. The trouble involves Python builds being sensitive to system dependencies, and older versions of Python requiring specific combinations of MSVC build tools for Windows.

Dominoes fucked around with this message at 09:46 on Sep 10, 2019

Dominoes
Sep 20, 2007

Active discussion

Data Graham
Dec 28, 2009

📈📊🍪😋



Dominoes posted:

Sweet. I'm not sure why I've had such trouble with VMs before; tried Docker to help someone repro a bug and got nowhere, despite most people having no trouble. Also having flashbacks of an old Django tutorial that used Vagrant/Chef/Virtualbox. Looks like Windows Subsys for Linux now supports several distros, which may help too.

Man I'm glad I'm not the only one for whom Docker seems like watching kids today with their intendos and wondering when I got so old.

Wasn't someone going to start an All Things Docker thread?

mbt
Aug 13, 2012

bashing my head against the wall irl trying to upload something to pypi, here's my folder layout:

code:
projectname(folder)
	readme.md
	licence
	setup.py
	projectname(folder)
		__init__.py
		projectname.py
	tests(folder)
		test_projectname.py
ive tried like 10 variations of things in the init trying to get it to import but no matter what it fails. it installs! but import fails.
(from . import projectname, import projectname, not declaring any import, nothing works)

please tell me where I hosed up so i can fix it and never interact with this again

i'm pretty sure the issue is in the init

Fluue
Jan 2, 2008

Malcolm XML posted:

The iron rule of dependency injection strongly suggests you do the latter. Your API wrapper should have no idea where it gets its keys.

Right. I'm asking whether it's better to init an instance of the API wrapper in the module itself or init the wrapper elsewhere (E.g. when it's needed).

This is running in an AWS lambda, btw, which typically advises creating reusable instances :shrug:

SurgicalOntologist
Jun 17, 2004

Meyers-Briggs Testicle posted:

bashing my head against the wall irl trying to upload something to pypi, here's my folder layout:

code:
projectname(folder)
	readme.md
	licence
	setup.py
	projectname(folder)
		__init__.py
		projectname.py
	tests(folder)
		test_projectname.py
ive tried like 10 variations of things in the init trying to get it to import but no matter what it fails. it installs! but import fails.
(from . import projectname, import projectname, not declaring any import, nothing works)

please tell me where I hosed up so i can fix it and never interact with this again

i'm pretty sure the issue is in the init

Read this: https://blog.ionelmc.ro/2014/05/25/python-packaging/

I recommend putting everything in src. Then if you only have one module (.py file) you don't need to bother with a package (folder containing an __init__.py). Just src > projectname.py.

But if you really want to make a module inside a package, your import path is essentially projectname.projectname.thing.

So your options are
1) empty __init__.py. From the interpreter, import like
code:
from projectname.projectname import thing
# or
import projectname.projectname.thing
2) __init__.py:
code:
from projectname import projectname
Interpreter:
code:
from projectname import thing
# or
import projectname.thing
3) __init__.py:
code:
from projectname.projectname import thing
Interpreter: same as (2). Would be different except that your module and package both have the same name.

Malcolm XML
Aug 8, 2009

I always knew it would end like this.

Fluue posted:

Right. I'm asking whether it's better to init an instance of the API wrapper in the module itself or init the wrapper elsewhere (E.g. when it's needed).

This is running in an AWS lambda, btw, which typically advises creating reusable instances :shrug:

The latter, again. For lambdas and scripts I ve always had a driver function that gets all of the config from wherever and then initializes the modules that do the work

Dominoes
Sep 20, 2007

Meyers-Briggs Testicle posted:

bashing my head against the wall irl trying to upload something to pypi, here's my folder layout:
i'm pretty sure the issue is in the init
I'm thinking the same. Post it. I'd recommend not titling your main script the same as your project, to avoid having 3 levels of same-name.

Dominoes fucked around with this message at 20:34 on Sep 10, 2019

Thermopyle
Jul 1, 2003

...the stupid are cocksure while the intelligent are full of doubt. —Bertrand Russell


I'm still not clear on how you're going to handle multiple conflicting versions of package X when you can't reliably refactor import statements in packages since many packages have dynamic imports with importlib.

With traditional methods you get a warning from, say poetry, during install if there's conflicting dependencies.

With your method it seems like your code will let you install conflicting dependencies, but then, since you can't be sure you refactored all import statements because of dynamic imports, the user won't know that their application won't work until they try to run it.

Or, worse, their application works, but its behavior is subtly different because its dynamically importing the wrong version of a dependency.

Dominoes
Sep 20, 2007

I haven't attacked importlib and dynamic imports yet, so that's an open question. If at least able to detect them, failing on them, but otherwise passing is still a better option than failing on all traditionally non-resolvable graphs. As you point out, hard-failing (Pipenv and Poetry's behavior) is better than undefined behavior.

Do you have an example on PyPi that uses importlib or dynamic imports I could test with?

edit: The stopgap may be failing all must-rename dependencies that use importlib. I suspect this, along with deps that use relative imports in compiled modules, represent a minority of cases.

Dominoes fucked around with this message at 21:51 on Sep 10, 2019

KICK BAMA KICK
Mar 2, 2009

New Humble Bundle of Python-related stuff has some books and videos IDK about but each of the three tiers includes a few months of a PyCharm Professional license (new users only) -- two months at $1, four at the average ~$13 and six at $20. Don't remember off the top of my head what Pro adds if you aren't doing any web/db type stuff but if you are you should absolutely try it out for a few bucks. Highlight for me with Django is Professional adds code completion for a ton of stuff the free version doesn't see cause I'm guessing it's attributes on objects Django cobbles together at runtime.

Thermopyle
Jul 1, 2003

...the stupid are cocksure while the intelligent are full of doubt. —Bertrand Russell

Dominoes posted:

I haven't attacked importlib and dynamic imports yet, so that's an open question. If at least able to detect them, failing on them, but otherwise passing is still a better option than failing on all traditionally non-resolvable graphs. As you point out, hard-failing (Pipenv and Poetry's behavior) is better than undefined behavior.

Do you have an example on PyPi that uses importlib or dynamic imports I could test with?

edit: The stopgap may be failing all must-rename dependencies that use importlib. I suspect this, along with deps that use relative imports in compiled modules, represent a minority of cases.

Django and DRF both do a lot of dynamic imports.

That's what all that stuff you configure in settings.py by a dotted path is.

Dominoes
Sep 20, 2007

Thermopyle posted:

Django and DRF both do a lot of dynamic imports.

That's what all that stuff you configure in settings.py by a dotted path is.
Thanks - had never used this myself; that was a great explanation to grok it.

Follow-up to the virtualization: Made it work by installing a few diff Linux versions from the Win10 store. Can't get the Py builds I made on one OS to work (fully) on any other! Not even diff versions of Ubuntu, Debian, two Win10 computers etc. Hoping the CPython team handles this. The Rust-compiled app itself appears to be cross-platform.

Adding functionality to run isolated scripts in their own env without configuring/managing it manually. This is a related Py wart that's somewhat different from normal package management. Decision's still up in the air, but going to parse the file's imports, then download the newest version, stored in a global venv under the script's name. Need to think how to deal with multiple scripts with the same name, cleaning up envs when you delete scripts etc. Quick+dirty solution for quick+dirty scripts.

Dominoes fucked around with this message at 06:18 on Sep 11, 2019

Boris Galerkin
Dec 17, 2011

I don't understand why I can't harass people online. Seriously, somebody please explain why I shouldn't be allowed to stalk others on social media!

Dominoes posted:

Adding functionality to run isolated scripts in their own env without configuring/managing it manually. This is a related Py wart that's somewhat different from normal package management. Decision's still up in the air, but going to parse the file's imports, then download the newest version, stored in a global venv under the script's name. Need to think how to deal with multiple scripts with the same name, cleaning up envs when you delete scripts etc. Quick+dirty solution for quick+dirty scripts.

Have you taken a look at pipx to see what they do?

It’s what I use to install python based CLI tools that I’m always using, like black, flake8, other tools I’ve wrote and packed mainly for myself.

Their workflow is basically “pipx install black” or something like that and now black is in your PATH and is isolated from everything else.

For running scripts (not CLI tools) in their own environment poetry lets me do “poetry run scriptname_or_pathtofile” and it works quite well too.

Boris Galerkin fucked around with this message at 07:20 on Sep 11, 2019

Dominoes
Sep 20, 2007

Boris Galerkin posted:

Have you taken a look at pipx to see what they do?

It’s what I use to install python based CLI tools that I’m always using, like black, flake8, other tools I’ve wrote and packed mainly for myself.

Their workflow is basically “pipx install black” or something like that and now black is in your PATH and is isolated from everything else.
Dope! Looks like that solves much of the awkwardness of dealing with Python CLI tools.

quote:

For running scripts (not CLI tools) in their own environment poetry lets me do “poetry run scriptname_or_pathtofile” and it works quite well too.
When I do this, I receive the error "Poetry could not find a pyproject.toml file"

(You've subtly pointed out a confusing term both in my post you quoted, and in the community: "script" may refer to one of two different things! It's already getting confusing in my code and docs. I think I'm going to use "script" to refer to a one-off file, and "CLI tool" for something like black or poetry)

Dominoes fucked around with this message at 07:42 on Sep 11, 2019

Boris Galerkin
Dec 17, 2011

I don't understand why I can't harass people online. Seriously, somebody please explain why I shouldn't be allowed to stalk others on social media!
Yeah my bad. I meant script in the sense of a script inside my python project folder which isn’t meant to be “installed”.

E: apparently that’s your same definition as well

death cob for cutie
Dec 30, 2006

dwarves won't delve no more
too much splatting down on Zot:4
Please help me understand a Django issue:

Python 3.6, Django 1.10*

code:
request.session['tasks'].append(request.POST['title'])
This does not properly append to the list stored in request.session['tasks']. This appears to be a known issue - except this page is thirteen years old. I've found a few blog posts on the issue suggesting to do something like "request.session.modified = True" or pulling the list out of session, modifying it, and reinserting it into the proper key in session - these are, again, very old pages. I can't seem to find anything modern on the topic, and unfortunately "list" is a common enough word that Google results get clogged with garbage. Normally I'd accept this, except I have a project where this works as expected:

code:
request.session['activity'].append([activity_result, result])
works just fine, repeatedly. I have a few other projects where this is the case as well. I assumed it was some weirdness with shoving something straight into the list right out of request.POST, so I tried this instead:

code:
new_task = request.POST['title']
request.session['tasks'].append(new_task)
with no luck. It appears the only option is to have "request.session.modified = True" somewhere else in the function, but I absolutely have projects where that doesn't occur. I also have projects from other students/staff that manipulate request.session in this way where nothing unexpected happens. I have multiple other projects where I'm shoving lists into session and appending them, and everything works as normal.

What am I missing? Other uses of session work just fine, nothing seems amiss in my settings or in other places in my project. I thought maybe 'tasks' was somehow reserved and tried different key names; I've tried storing strings, ints, tuples, lists, etc. inside the list in session. I've tried multiple iterations of code and can't seem to pin down anything other than "works in other projects, doesn't work here". I'm wondering if I made some small mistake upfront and I'm just continually missing it?

* I teach** intro web development with a company that insists we use Django 1.10 instead of 1.11 for some reason; I appear to have the same problem in 1.11 as well, although I haven't tested as extensively.
** this post may not inspire much faith in my ability to teach - trust me, I'm not having much faith in this today, either

mbt
Aug 13, 2012

Dominoes posted:

I'm thinking the same. Post it. I'd recommend not titling your main script the same as your project, to avoid having 3 levels of same-name.

https://github.com/MortimerMcMire/cyclist

tell me where I went wrong please :(

preferably related to pypi but im open to all critiques

Thermopyle
Jul 1, 2003

...the stupid are cocksure while the intelligent are full of doubt. —Bertrand Russell

Epsilon Plus posted:

Please help me understand a Django issue:


I used to know the answer to this long ago, but I can't recall offhand. The session in 1.11 is implemented here.

I don't really feel like tracing through this anymore, mainly because I can't reproduce your issue. If you can give a minimal example project showing the issue I'll look into it more. Otherwise, you'll just have to examine the code linked to above. My first thought is it's going to have something to do with the __getitem__ method and/or the _get_session method/property and python's unique pass-by-object-reference model.

Also, if you can pin it down to working in one version of Django and not the other, you can diff that class to see what changed.

Keep us updated!

Dominoes
Sep 20, 2007

Meyers-Briggs Testicle posted:

https://github.com/MortimerMcMire/cyclist

tell me where I went wrong please :(

preferably related to pypi but im open to all critiques
What happens if you replace the contents of `__init__.py` with `from .cycle_events import *` ?

Warbird
May 23, 2012

America's Favorite Dumbass

Can anyone point me in the direction of a breakdown of installing OpenCV on a RasPi? I've gone through a few now and they've all just been nightmares of dependencies, omitted steps, depreciated projects, and some egregious spelling.

Evrart Claire
Jan 11, 2008
Humble Bundle has a python bundle again, https://www.humblebundle.com/level-up-your-python. I'm starting to apply again to some PhD programs for numerical analysis and machine learning, and Python commonly comes up as a desired language. I'm pretty used to doing math stuff in MATLAB and C, but less so in Python. Admittedly I'm a couple years out of my masters' now and had to settle for a job outside my field so pretty rusty on what I do know. How useful would the books/tools in this bundle be to self-teaching myself some python compared to whatever free online (or cheaper books) I could find out there?

QuarkJets
Sep 8, 2008

Warbird posted:

Can anyone point me in the direction of a breakdown of installing OpenCV on a RasPi? I've gone through a few now and they've all just been nightmares of dependencies, omitted steps, depreciated projects, and some egregious spelling.

Step 1) Install the raspberry pi version of miniconda
Step 2) Activate the conda environment
Step 3) Use the conda command to install opencv
Step 4) If for some reason that doesn't work, create a fresh conda environment and try again
Step 5) If for some reason that doesn't work, create a fresh conda environment and try installing with pip

CarForumPoster
Jun 26, 2013

⚡POWER⚡

Zerilan posted:

Humble Bundle has a python bundle again, https://www.humblebundle.com/level-up-your-python. I'm starting to apply again to some PhD programs for numerical analysis and machine learning, and Python commonly comes up as a desired language. I'm pretty used to doing math stuff in MATLAB and C, but less so in Python. Admittedly I'm a couple years out of my masters' now and had to settle for a job outside my field so pretty rusty on what I do know. How useful would the books/tools in this bundle be to self-teaching myself some python compared to whatever free online (or cheaper books) I could find out there?

IMO the best way to learn python is to find something you want to do and do it. There’s a stack overflow post or github pull request for literally everything.

KICK BAMA KICK
Mar 2, 2009

Zerilan posted:

Humble Bundle has a python bundle again, https://www.humblebundle.com/level-up-your-python. I'm starting to apply again to some PhD programs for numerical analysis and machine learning, and Python commonly comes up as a desired language. I'm pretty used to doing math stuff in MATLAB and C, but less so in Python. Admittedly I'm a couple years out of my masters' now and had to settle for a job outside my field so pretty rusty on what I do know. How useful would the books/tools in this bundle be to self-teaching myself some python compared to whatever free online (or cheaper books) I could find out there?
None of those books/videos look like the standard "learn Python" recommendations (IDK anything about those fields so I'm not sure if the ones specifically about like Pandas would be relevant to your interests). But PyCharm is the most common IDE for Python, and I think some of the features the Professional edition adds do relate to math/scientific/data libraries like NumPy, which I'm guessing you'd find yourself using at some point, so those licenses in the bundles are a great value (like $89 for a year standard but maybe you can swing an educational discount?). My suggestion: set the reminder on that bundle, install the free edition of PyCharm, start learning from whatever resource you find/someone else here recommends, and if you think you're gonna keep using it grab that 6-month Professional license at the $20 tier, can't lose at that price.

Warbird posted:

Can anyone point me in the direction of a breakdown of installing OpenCV on a RasPi? I've gone through a few now and they've all just been nightmares of dependencies, omitted steps, depreciated projects, and some egregious spelling.
Definitely try what QuarkJets said but if you must compile for whatever reason, this worked for me on a 3B (with maybe one or two substitutions even I was able to figure out, and I am dumb) and includes the flags that enable some optimizations for the Pi's chips.

Warbird
May 23, 2012

America's Favorite Dumbass

QuarkJets posted:

Step 1) Install the raspberry pi version of miniconda
Step 2) Activate the conda environment
Step 3) Use the conda command to install opencv
Step 4) If for some reason that doesn't work, create a fresh conda environment and try again
Step 5) If for some reason that doesn't work, create a fresh conda environment and try installing with pip

I remember there being another sort of setup like this and I broke it all to hell; I historically haven't had much like with Python. I'll give it a shot and see what happens. I'm attempting to do this on a 0W though so it seems like that's far beyond reason.

Adbot
ADBOT LOVES YOU

CarForumPoster
Jun 26, 2013

⚡POWER⚡
I can't think of a super easy way to do this and I bet there is one.

I have a pandas df:
code:
id|name|attrs
123|bob|[cool,old,man]
456|dave|[uncool,old,man]
I want:
code:
id|name|attrs
123|bob|cool
123|bob|old
123|bob|man
456|dave|uncool
456|dave|old
456|dave|man
Whats the pythonic/pandas way to do this for a list (df['attrs'][index]) of arbitrary length?

CarForumPoster fucked around with this message at 14:19 on Sep 14, 2019

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