[ / / / / / / / / / / / / / ] [ dir / random / cloveros / cuteboys / erp / fast / hydrus / in / strek / tftg ]

/g/ - Technology

Make /g/ Great Again
Name
Email
Subject
Comment *
File
Password (Randomized for file and post deletion; you may also set your own.)
Archive
* = required field[▶ Show post options & limits]
Confused? See the FAQ.
Embed
(replaces files and can be used instead)
Voice recorder Show voice recorder

(the Stop button will be clickable 5 seconds after you press Record)
Options
dicesidesmodifier

Allowed file types:jpg, jpeg, gif, png, webm, mp4, swf, pdf
Max filesize is 16 MB.
Max image dimensions are 15000 x 15000.
You may upload 5 per post.


File: 666150a0c4ea3c1⋯.jpg (59.98 KB, 607x300, 607:300, 1504066439186.jpg)

 No.8328

How can I store multiple strings to variables automatically, in Python?

cmdFindListCards=Popen("ifconfig -a | grep Link | cut -d ' ' -f1", shell=True, stdout=PIPE, universal_newlines=True)
listCards=cmdFindListCards.communicate()[0].rstrip()

I don't know if we've got the [code] tag enabled here.

The output of the first line is:

docker0

enp1s0

lo

vboxnet0

wlan1

How can I make Python automatically create one variable for each line, in which the variable is assigned to the value of that string (the interface name), like this?:

card1=docker0 (first line value)

card2=enp2s0 (second line value)

card3=lo (third line value)

____________________________
Disclaimer: this post and the subject matter and contents thereof - text, media, or otherwise - do not necessarily reflect the views of the 8kun administration.

 No.8329

I meant "The output of the first line of code is:"

Disclaimer: this post and the subject matter and contents thereof - text, media, or otherwise - do not necessarily reflect the views of the 8kun administration.

 No.8386

This is what arrays/collections are for

Disclaimer: this post and the subject matter and contents thereof - text, media, or otherwise - do not necessarily reflect the views of the 8kun administration.

 No.8424

>>8328

in python you can literally do card1, card2, card3 = listCards, as long as the lengths are the same

Disclaimer: this post and the subject matter and contents thereof - text, media, or otherwise - do not necessarily reflect the views of the 8kun administration.

 No.8999

>>8328

Use "exec"

Disclaimer: this post and the subject matter and contents thereof - text, media, or otherwise - do not necessarily reflect the views of the 8kun administration.



[Return][Go to top][Catalog][Nerve Center][Random][Post a Reply]
Delete Post [ ]
[]
[ / / / / / / / / / / / / / ] [ dir / random / cloveros / cuteboys / erp / fast / hydrus / in / strek / tftg ]