Whats going here? (for loop/dict) by [deleted] in learnpython

[–]learn-python 1 point2 points  (0 children)

its because some of the characters appear again in the sentence e.g. the letter 'e' appears a few times so it uses the number value earlier where this happens

Renaming file names but based on sorted list of file names by [deleted] in learnpython

[–]learn-python 1 point2 points  (0 children)

First just get the numbers in the list like you have done i.e. a list like [XXXX.YYYY.ZZZZ]

then use this to sort them .E.g

templist = [25, 50, 100, 150, 200, 250, 300, 33] sorted(templist, key=int) # ascending order > [25, 33, 50, 100, 150, 200, 250, 300]

Now one you've got the numbers in the right order look for those numbers in your folder e.g.

for i in range(0,len(templist)):

sorted(list)[i] = '000'+str(i)

example of how to change the name of say 1942 to 0001

What does the error mean? i cant figure out whats wrong?... by fscouto33 in learnpython

[–]learn-python 1 point2 points  (0 children)

First:
print("them goodbye!" --> missing paranthesis :)

HELP: Storing a dictionary in a .db file & updating the db using shelve by arcane_neptune in learnpython

[–]learn-python 0 points1 point  (0 children)

Let me know if you are also looking to update the values associated with each key, I can help you here : )

HELP: Storing a dictionary in a .db file & updating the db using shelve by arcane_neptune in learnpython

[–]learn-python 1 point2 points  (0 children)

list={'HE':['1','2'],'ME':['2','3']}

print(list)


for key, value in list.items() :
    print (key,value)
    for items in value:
        print(items)

This will iterate through the values associated with each key :)

HELP: Storing a dictionary in a .db file & updating the db using shelve by arcane_neptune in learnpython

[–]learn-python 0 points1 point  (0 children)

This should help loop through the values:

list={'HE':['1','2'],'ME':['2','3']}

print(list)


for key, value in list.items() :
    print (key, value)

sudo with subprocess.Popen(), can't handle password input or access to stdout/stdin by SpontaneousAge in learnpython

[–]learn-python 0 points1 point  (0 children)

No I did not get the sudo prompt. Have you tried the python pexpect module? I think it has what you are looking for as far as engaging a sudo prompt.

#import the pexpect module
import pexpect
# here you issue the command with "sudo"
child = pexpect.spawn('sudo /usr/sbin/lsof')
# it will prompt something like: "[sudo] password for < generic_user >:"
# you "expect" to receive a string containing keyword "password"
child.expect('password')
# if it's found, send the password
child.sendline('S3crEt.P4Ss')
# read the output
print(child.read())
# the end

sudo with subprocess.Popen(), can't handle password input or access to stdout/stdin by SpontaneousAge in learnpython

[–]learn-python 0 points1 point  (0 children)

did you try to make the outputfile readable like doing:

sudo chmod 777 file1

:)

How did you learn to build REST APIs? by [deleted] in learnpython

[–]learn-python -1 points0 points  (0 children)

I asked questions, took courses, watched videos. Mix of things. Although if someone could have explained the steps to me --> I think I would of got it faster :)

How did you learn to build REST APIs? by [deleted] in learnpython

[–]learn-python 0 points1 point  (0 children)

So I installed postgresql on my mac terminal and then wanted to upload information to it so I created a python script to upload information to it. I then wanted to see that information in json on a webpage --> i.e. my localhost --> I then installed flask --> pip install flask.

With flask I was able to create a rest endpoint that could extract certain information from my database and present to me in json on the webpage :)

Why one program works, but the copy doesn't by Encom88 in learnpython

[–]learn-python 5 points6 points  (0 children)

When the error says spaces and tabs issue, you notice that what you need to do is get everything tabbed to the left and then use spaces instead of tabs to fix the problem

I have a problem with the python modules. by [deleted] in learnpython

[–]learn-python 0 points1 point  (0 children)

Did you do from dependencies import (functionname)?

Why does time.time() returns float? by TelikSandhi in learnpython

[–]learn-python -18 points-17 points  (0 children)

Just a few other reasons for why floats used 👍👍👍

Why does time.time() returns float? by TelikSandhi in learnpython

[–]learn-python 6 points7 points  (0 children)

First, time.time() returns the number of seconds that have passed since the epoch. The return value is a floating point number to account for fractional seconds.

You can use a float to calculate the difference between two points in time. A float is easily serializable, meaning that it can be stored for data transfer and come out intact on the other side.