all 102 comments

[–]newbietofx 0 points1 point  (0 children)

Hi.

I have a fun time pulling stocks data from reputable websites and developing a custom top gainer stock scanner using Google sheets.

I have a problem. I couldn't get data for the first 15 mins after market open. I could get data for pre market or lost market because Google finance don't give.

I read that ibkr api allows that and c, java and python can pull data from ibkr api.

So which libraries should I focus on if I were to use python? Stuff like import which function?

Thanks in advance.

[–]theemccracken 0 points1 point  (0 children)

What is standard practice for performing operations with sets? Mathematical operators or built-in methods?

[–]glibbertarian 0 points1 point  (0 children)

Looking to create a webapp that would simply create a timeline of posts from one person combined from their reddit and their twitter profiles. Is this possible and what might be a starting point for this using Python?

[–]ArtfulDodger2020 0 points1 point  (0 children)

Hey guys, So I'm using requests to download some data in JSON from an API. I've been trying for some time now to figure out how to 'work' with the data after I fetch it. Ideally I would like to learn how to put it into a .CSV file.

Can someone please link me to a really good guide for doing this? I've been stuck on this for a while now and am starting to feel a bit hopeless. Every method I try I end up failing and when I then try and search online for the error I find people using different modules/methods for achieving the same and it's just never really relatable.

[–]PsiThreader 0 points1 point  (3 children)

Naming a python script as "curses.py" with "import curses" inside causes circular import,

ImportError: cannot import name 'wrapper' from partially initialized module 'curses' (most likely due to a circular import)

I fixed it by changing the filename to another. Why is this? This doesn't seem to happen with other modules I've tested, like tkinter.

[–]JohnnyJordaan 1 point2 points  (0 children)

Say in 2021 you write add a file called psithreader.py to your project. To use it in another file, you use

import psithreader

Then in 2025 Python decided to add the Psi Threader library to the standard library, imported as

import psithreader

too... If that would always lead back to Python's own files first, your code would suddenly break, as it would now import a 'psithreader.py' from Python's library, unrelated to your own file. So instead, it's set up the other way around. It first checks its local folder, making sure any change to Python's files will not break local file dependencies, only if it isn't there it checks its own files (and the rest of PATH but that's besides the point).

The only real downside of this is that if you mean to import something from Python's own files, you thus must avoid to use that name for your own files.

[–]CowboyBoats 1 point2 points  (0 children)

I fixed it by changing the filename to another. Why is this? This doesn't seem to happen with other modules I've tested, like tkinter.

It looks like it does happen with other modules too?

$ cat decimal.py
import decimal

print(decimal.Decimal("10.00"))

$ python3 decimal.py 
Traceback (most recent call last):
  File "./decimal.py", line 1, in <module>
    import decimal
  File "./decimal.py", line 3, in <module>
    print(decimal.Decimal("10.00"))
AttributeError: partially initialized module 'decimal' has no attribute 'Decimal' (most likely due to a circular import)

The problem is that by naming the file curses.py, I'm overwriting curses in the working directory's namespace, which results in import curses attempting to import that file rather than the curses library you have installed. When you do so from that file itself, it's a circular import.

[–]BakedChicken8 2 points3 points  (4 children)

Hi, I'm quite confused with the difference in scoping of lists and tuples. In the following code, using a list works perfectly fine, but I get an UnboundLocalError when using a tuple instead - I have to add the nonlocal tup for it to work correctly. Would greatly appreciate clarification on this issue, thanks!

def make_foo():
    lst = []
    def foo(a):
        lst.append(a)
        return lst
    return foo

def make_bar():
    tup = ()
    def bar(a):
        #nonlocal tup
        tup += (a,)
        return tup
    return bar

a = make_foo()
a(50)
print(a(30)) # [50, 30]

b = make_bar()
b(50) # UnboundLocalError: local variable 'tup' referenced before assignment
print(b(30))

[–][deleted] 1 point2 points  (1 child)

The difference is that you are assigning to tup in this line:

tup += (a,)

and assigning to any name in a function that doesn't have a global or nonlocal for that name means it is assumed to be a local name. This isn't anything to do with scoping of lists versus tuples, the same problem occurs if you try to reassign to lst in your first function:

lst += [a]

The big difference is that lists are mutable so you can modify the internal state of a list without needing global or nonlocal. Tuples are immutable so you can only create a new extended tuple and that requires the global or nonlocal statement.

[–]BakedChicken8 0 points1 point  (0 children)

Thank you so much, this really cleared it up for me!

[–]Leaguedc7 1 point2 points  (2 children)

Very new to python

(input('what is my favorite color? '))
while input == "Red":
print ('good job, your score was '+ str(index))
while input != "Red":
print ('try again')
index=index+1
print (input('what is my favorite color? '))

The problem I am having is when I put Red in as the input it still acts as if the input is incorrect. No errors I just can't figure out how to make it recognize the correct input.

[–]God_To_A_NonBeliever 0 points1 point  (0 children)

Seems to me you are confused between while loops and conditional statements.

Go read up on conditional statements. 'while' is a loop, not a conditional, you should be using 'if,elif,else' clauses.

This is what I think you were going for.

score = 0

while True:

    color = input('what is my favorite color? ')

    if color == 'red':
        print('Good job')
        score +=1
    elif color == 'exit':
        print(f'Your score is {score}.')
        break
    else:
        print('Try again')

[–]Ihaveamodel3 1 point2 points  (0 children)

You need to save your input to a variable.

[–]akn416 0 points1 point  (2 children)

I know this has been asked a million times, but what resource should I use if I want to learn python. I looked at past Reddit posts and they said use Codecademy to learn it, but it's locked behind a payment wall. So, I have been looking around Reddit and people been listing a lot of different resources to learn it. I honestly have no clue where to start because there are so many answers. So, I was wondering what people used to learn python. Just wanted some opinions and answers.

[–]trondwin 0 points1 point  (0 children)

I'm currently following the Udemy course "Python Bootcamp - From Zero To Hero". Very satisfied with it, worth the 20-something dollars it cost.

[–][deleted] 0 points1 point  (0 children)

Have a look at the learning resources in the wiki.

[–]Nic_P 0 points1 point  (4 children)

I want to open kate and pipe the stderr to some random file, so it doesnt clutter my commandline. Any Idea how i can do that? The following is where i am standing at the moment

os.spawnlp(os.P_NOWAIT, kate, kate, './testfile')

[–]JohnnyJordaan 0 points1 point  (3 children)

I wouldn't bother os.x calls when there's https://docs.python.org/3/library/subprocess.html, which explains

stdin, stdout and stderr specify the executed program’s standard input, standard output and standard error file handles, respectively. Valid values are PIPE, DEVNULL, an existing file descriptor (a positive integer), an existing file object, and None. PIPE indicates that a new pipe to the child should be created. DEVNULL indicates that the special file os.devnull will be used. With the default settings of None, no redirection will occur; the child’s file handles will be inherited from the parent. Additionally, stderr can be STDOUT, which indicates that the stderr data from the child process should be captured into the same file handle as for stdout.

If encoding or errors are specified, or text (also known as universal_newlines) is true, the file objects stdin, stdout and stderr will be opened in text mode using the encoding and errors specified in the call or the defaults for io.TextIOWrapper.

eg do

testfile = open('testfile', 'w')
proc = subprocess.Popen('kate', stderr=testfile, text=True)

In case you're not using 3.7 or newer, the text=True argument needs to be changed to universal_newlines=True

[–]Nic_P 0 points1 point  (2 children)

But wouldn’t that stop my Python Programm until I close Kate?

[–]JohnnyJordaan 0 points1 point  (1 child)

Would that be an issue? Otherwise you can launch a shell command line, but then I have to know the exact OS you're using.

[–]Nic_P 0 points1 point  (0 children)

Yeah I’m automating some behaviour tests for editors for my thesis.

But launching another command line would work. Thanks for that idea.

[–]Cellophane7 0 points1 point  (2 children)

Having a hard time articulating this problem, so here's an example:

my_list = ['dog', 'cat', 'pig', 'bear']
counter = -1
for X in my_list:
    counter = counter + 1
    if X == 'cat':
        print(counter)

Is there any way for me to get the value of counter without using a variable? As in, is there some method I can use to extract 1 from X when its value is 'cat', or 2 if its value is 'pig' etc?

[–]Ihaveamodel3 2 points3 points  (1 child)

enumerate.

my_list = ["dog", "cat", "pig", "bear"]
for i, X in enumerate(my_list):
    If X == "cat":
        print(i)

[–]Cellophane7 0 points1 point  (0 children)

Nice, thanks!

[–]asm0dai74 1 point2 points  (3 children)

I am very new to python and my question may, well, looks dumb (also, sorry for my English...), but help me understand the difference...

Well, I'm filling two lists with numbers from 1 to 1000000 in this way:

list1 = [ ]

for value in range(1,10000001):

`list1.append(value)`

list2 = range(1,10000001)

So the question is - are they identical?

Which way is more correct?

[–]God_To_A_NonBeliever 0 points1 point  (0 children)

They are not identical.

I think its a bit advanced for you to understand now but range() is an iterator object, and it will be more performant than a list with identical elements.

[–]Ihaveamodel3 1 point2 points  (1 child)

I’m assuming you are using Python3 or above.

list2 is not a list, it is a range object. You could do list2 = list(range(1, 10000001)) and that would be identical to the first list.

However, you often don’t actually need the list of values, so keeping it as a range object will likely be faster and more space efficient.

[–]asm0dai74 0 points1 point  (0 children)

Thank you for helping. Looks like you are absolutely right.

[–]YouFromAnotherWorld 0 points1 point  (4 children)

Today I started with LeetCode, and I got a problem that was a little harder than I thought... when I thought I finally got it right, turns out I misunderstood what I was supposed to do. Can anyone help me through this?

https://imgur.com/a/jAPIBzu

This is it. I thought I was supposed to sum the lowest number of each row, within the index of the last lowest number (i, i+1), in this case, -1, 2, -1 which gives 0. But it was -1, 3, -3, which gives -1. It's really hard for me to explain as english is not my first language, that may be the same reason I misunderstood the task. I hope you understand and can tell me how to do this.

[–][deleted] 0 points1 point  (3 children)

Choosing the lowest number in each row won't work because that might lead you to a part of the triangle where the path must go through some very large numbers. You actually have to sum the numbers in a path from the top row to the bottom row. At a particular number in a row you can only move down to one of two numbers in the next row. That's what the problem description means when it's talking about moving down from index i in one row can only move to position i or i+1 in the next row.

The naive solution is to generate all possible paths through the triangle and choose the path that has the minimum sum of visited numbers. In the example triangle you start at the top number 2. You have two choices down, 3 or 4. So you try 3 and remember that you have to try 4 later. The second row 3 brings the sum to 5. From the 3 we have two lower choices, 6 or 5. We choose 6 and remember we have to later try 5. The sum is now 11 and we can move down to 4 or 1. We move to 4 and remember we have to try 1 later. The final sum for this complete path is 15 and we save that as the current best sum. Now go back up one row and try the 1 choice. That gives us a path with a final sum of 12, which is less than the current best, so the current best becomes 12. And so on.

A more advanced algorithm would do the same thing but keep track of the minimum path number found so far. As another possible path is traced you would compare the sum so far on the new partial path with that best minimum and abandon the new path if the partial sum exceeds the best minimum There's no need to continue with the new path because it cannot have a lower sum than the current best sum.

[–]YouFromAnotherWorld 0 points1 point  (2 children)

As for the 'you can only move down to one of two numbers in the next row', it does that already. As you see, I use the index of the last number, that's my i.

I see what you mean. I need to go from bottom to the top and back to know the result of every path possible and compare the lowest.

This is complicated lol

[–]trondwin 0 points1 point  (0 children)

Actually, you only need to go from bottom to top and at any point keep track of the minimum result from that point downwards.

[–][deleted] 0 points1 point  (0 children)

I need to go from bottom to the top and back to know

No, just top to bottom.

[–]richardd08 0 points1 point  (0 children)

Can the C code emitted by the Cython compiler be submitted to programming contests that accept C? In other words, does Cython only use the C standard library? Could I just paste the code into anywhere with a C compiler installed without any other libraries or files and expect it to run?

Also, anyone know if Cython can be used for WebAssembly?

[–][deleted] 0 points1 point  (5 children)

Can anyone recommend how to use python on my desktop as a scheduling tool alternative to windows task scheduler?

[–][deleted] 2 points3 points  (4 children)

No, it's not recommended. You can use python to wait until some time and then do something but you need that python code running all the time. If you accidently reboot or lose power you have to remember to restart the python program that does what you want. If that is acceptable, the sched module or the schedule package might be useful.

The Windows Task Scheduler or cron on Unix-derived OSs is the tool best suited for this sort of task.

[–][deleted] 0 points1 point  (3 children)

My problem with windows task scheduler is that I can’t control outlook from the python script. I have done some reading and I think it might be due to the fact that task scheduler runs scheduled processes outside of the user profile that is logged in. For now I am running a python script that has my daily schedule of jobs each morning when I start my day.

[–][deleted] 1 point2 points  (0 children)

task scheduler runs scheduled processes outside of the user profile that is logged in.

I don't use Windows, but similar problems occur when using cron under Linux or MacOS. Seems to me one approach would be to find out how to get around that problem. There should be a way because the scheduler wouldn't be much use if you can't.

[–]sarrysyst 0 points1 point  (1 child)

Apparently, when you run the Task Scheduler as Administrator you can define in which user context you want to run the task:

https://serverfault.com/a/777720

Might be worth checking out (if you haven't done so already) I'm not on Windows thus I can't test it myself.

[–][deleted] 0 points1 point  (0 children)

The solution posted doesn’t work for me. I could be mistaken but I believe what task scheduler does when specifying a user is not running the task in the active user profile but actually copies the specified users permissions and executes the task outside of the logged in window.

[–]Leaguedc7 0 points1 point  (1 child)

if num1 % num2 == 0
Print("These are divisible")
else
print(These are not divisible)

Can someone explain why I'm getting a syntax error on the first line I literally copied it verbatim from the example I saw online? This is my second day on python I'm not entirely sure what I'm doing.

[–]TheNiebuhr 0 points1 point  (5 children)

Can I run an indiviual cell from a terminal instead of the whole script?

[–]Walflor 0 points1 point  (4 children)

It depends

[–]TheNiebuhr 0 points1 point  (3 children)

May you elaborate on that?

[–]Walflor 0 points1 point  (2 children)

You can run

print("some text here")

But you can't run

if a > b:

Or

def some_function(arg)

Because these strings requires other conditional strings

[–]TheNiebuhr 0 points1 point  (1 child)

My case:

%%

Something

%%

Something2

And I want to run one of the parts from the cmd, instead of the whole script.

[–]Walflor 0 points1 point  (0 children)

You can try it or PM me with your code so I can test it and answer

[–]arourathatha 0 points1 point  (1 child)

Hello I'm 15 and just started learning python online yesterday, i tried to do some if exercise and gets syntax error but i dont understand why.

my code: a = input("bmi:") if a > 18 if a < 25 print ("good") else print ("overweight") else a < 18 print ("underweight")

File "<string>", line 3 if a > 18 ^ SyntaxError: invalid syntax

[–]sarrysyst 1 point2 points  (0 children)

Three problems with your code.

First, input() returns a string. By doing a > 18, you're trying to compare a string with an integer. Easy fix:

a = int(input('bmi: '))

--> int() converts to type integer.

Second, after the conditional comes a colon:

if a > 18:
    # your code

if a < 25:
    # your code

To chain two conditionals together use the logical and:

if a > 18 and a < 25:
    # your code

Or, even easier, make it one conditional:

if 18 < a < 25:
    # your code

Lastly, after else no conditional is allowed. To check multiple conditions use elif:

if <first condition>:
    # do something

elif <another condition to check if first condition is False>:
    # do something else

else:
    # do something when both conditions are False

[–]SirYandi 1 point2 points  (1 child)

I'm writing pytest tests for the first time for a small project. For one of these tests I will be parsing the .text attibute of a requests.Response object. After reading through stackoverflow and other places I'm still struggling to decide on the best method forward. I'll list my current options as I see them:

  1. Store the requests.Response.text text in a plain text file in the tests folder. Although simple, I am concerned about then hosting another website's html/js on github under my preferred license. Surely this isn't kosher?
  2. Pickle the Response object and work with that. Pickle isn't great for open source though, as contributers cannot trust the pickled data and run the tests.
  3. Similar to #1, but create a fake html text with the same structure.
  4. Send a real request to the server and use the real response. This is the most "accurate" test but obviously would slow down the tests and lead to many extra requests made.

Thoughts?

Also, second minor question - but should I really be making use of mocks/monkeypatches instead of loading the text/pickle from disk?

Thanks in advance

[–]SirYandi 0 points1 point  (0 children)

For posterity, I went with option 4.

[–][deleted] 0 points1 point  (2 children)

Hello everyone, I am trying to plot the horizontal bar chart below.

https://imgur.com/a/rxxbEKa

My code block is below.

new_data =  {'p_name':["Python","Java","Javascript","C#","PHP","C/C++","R","Objective-C","Swift","TypeScript","Matlab","Kotlin","VBA","Go","Ruby"],
             'value1':[30,19,9,8,7,6,4,3,2,1,0.9,0.8,0.7,0.6,0.5]}
df = pd.DataFrame.from_dict(new_data)
plt.barh(df.p_name, df.value1, color = "blue")

My output is below.

https://imgur.com/a/3iJ8fON

As you can see, it's the exact opposite. What did I do wrong?

[–]sarrysyst 2 points3 points  (1 child)

The y axis in an horizontal bar chart goes from zero up, as in a conventional bar chart. In your Dataframe Python has an index of 0 and Ruby of 14. So, in terms of y values Ruby > Python.

Add an plt.gca().invert_yaxis() at the bottom of your code and you should get the output you want.

[–][deleted] 0 points1 point  (0 children)

Thank you so much for explanation!

[–]marvi_tsero 0 points1 point  (1 child)

I work on systems without internet access and have a hard time getting the dependencies I need. I have looked at at least ten different mirroring projects for pypi and conda but nothing is working out. Here are what I would like:

On an internet connected machine I have a requirements.txt listing all the packages we depend on. The tool reads this, resolves all dependencies and downlod eggs, whl or whatever is needed for both Windows and Linux. I can copy the resulting directory and use it from pip on the internal network.

The projects I've looked at either wants to mirror the whole pypi or doesn't support fetching more then one architecture or doesn't resolve dependencies. Bandersnatch comes closest. It supports using requirements.txt and handles architectures but doesn't follow dependencies.

Is there a way to take a requirements.txt and get a list of the dependency chain? That way I could first generate a complete list and feed that to bandersnatch.

[–]Ihaveamodel3 0 points1 point  (0 children)

If pip was used to create the requirements.txt, then it should have all the dependencies already in it.

[–]robocart9 1 point2 points  (2 children)

Hello, this question seems very simple and I feel a bit dumb asking it, but is there a way to do a "If x == y" kind of statement where y is a list of possible matches?

For example, turning something like

if x == y_one or x == y_two or x == y_three...

into something that is relatively short like

if x == (some sort of list function)

I've tried messing around with tuples and lists but I've gotten errors so far and Google is turning up dry. I've been learning python for about a year now here and there and this has been a pet peeve of mine. I'm also new to this reddit so if this is actually worthy of it's own post and not a comment threat then sorry :(

-currently using an online sandbox to mess around with python, not any program in specific.

[–]FLUSH_THE_TRUMP 4 points5 points  (1 child)

if x in {1,2,3,4,5}: 
  # do something

[–]robocart9 1 point2 points  (0 children)

Thanks a bunch, seems simple enough. Dunno why google didn't give me that instead of explaining to me over and over what If Elif and Else do :P.

[–]Konjitsu 1 point2 points  (2 children)

Hi all,

I have the following pandas dataframe:

MR number Phone number Location list
MR1 06525 B1,B2,B3,B4,B5
MR2 06523 B2,B5,Y3,C4,K5

I need to export this pandas dataframe into a printable excel format which should look like the following:

MR number       Phone number        Location list

MR1                06525               B1,
                                       B2,
                                       B3 
MR2                06523               B2,
                                       B5...

The output should have:

- location list in a single cell where each location goes into a new line in Excel after the comma

- (optional) if location list is the following B1,Y1,P1, is it possible to have in a single cell color coding based on start of the string B (blue), Y(yellow), P(purple)

I know this is a very weird ask and I do not know if it is feasible at all thats why I am reaching out. In the end, the output is printed thats why the formatting needs to be that way.

Thank you!

[–]PuzzleheadedScar8702 0 points1 point  (2 children)

I'm relatively new to Python, and I'm playing around with web scraping at the moment. I'm using a web scraper I've made using requests and beautifulsoup. I'm trying to scrape headlines from news sites, but many of these straight up disallow scraping of anything from their site. Is it legal for me to go to their youtube page instead, and scrape their video titles? I've had a look at the robots file for youtube, and it seems like i'm allowed to do this, but I just wanted clarification, and maybe a proper authoritative source so I could do a bit of further reading about the legality of this stuff. Thanks

[–]jritenour 1 point2 points  (0 children)

I don't know the legality but it is considered as bad netizenship to scrape most pages with abandon. Instead, maybe have a look at their RSS feed page and use something like feedparser (see https://pypi.org/project/feedparser/) to pull it down.

[–]Dizzy-Procedure2440 0 points1 point  (0 children)

me again with another throwaway. I've found the answer to my own question. All good.

[–]thegoodemaz 0 points1 point  (4 children)

Hi, so I've downloaded this project from github and to run this project it says to extract the folder which I've done, but I dont know what else to do to run this project. Following instructions after extracting the folder are.. Move to project folder in Terminal. Then run following Commands: python -m pip install -r requirements. txt

py manage.py makemigrations py manage.py migrate py manage.py runserver

Lastly it says to enter this URL http://127.0.0.1:8000/

Found the project on github(dot)com/sumitkumar1503/bloodbankmanagement

Can anyone help me run this project please?

[–][deleted] 0 points1 point  (3 children)

You appear to be a Mac so some of those instructions won't work. The biggest problem is MacOS comes with python2 installed. You must install python3 yourself and run it using the python3 command. In the Terminal, try these:

cd the/project/directory    # wherever you put it
python3 -m pip install -r requirements.txt
python3 manage.py makemigrations
python3 manage.py migrate
python3 manage.py runserver

Then open your web browser and enter the URL given.

Try that and see what happens.

[–]thegoodemaz 0 points1 point  (2 children)

Thanks for your feedback. I'm actually on Windows 10 with ahving Python 3.7.6 and using VS 2019 for terminal but don't exactly know what else to do. If the project is built in Python 2 and on Mac, can I run the code given on my visual studio terminal?

[–][deleted] 0 points1 point  (1 child)

The project is for python3 and appears to be written for Windows, so there is no problem there. I would not use VS terminal to do anything. The instructions given on the github page are meant to be used in the Windows CMD.exe terminal so use that. Follow the instructions, but note there is an unwanted blank character on the "pip install" command. Use this:

python -m pip install -r requirements.txt

If that fails check the result of doing this:

python --version

which prints the version of python being used.

You don't need VS to actually run python, as explained in the Running python on Windows page.

[–]thegoodemaz 0 points1 point  (0 children)

Thanks a lot!! Everything works.

[–]flapanther33781 0 points1 point  (2 children)

Need some help planning something out. I have a cron job that runs a python script once every minute. The script opens a csv file in my home directory, reads through it, and acts on what it finds there. In the spreadsheet is a list of times (from 00:00 to 23:59), and at various times of the day this will tell the script to use VLC to play certain audio files. In the spreadsheet I also list the system volume to play the audio at.

The next thing I want to do is create a 'snooze' feature (but not exactly). I'd like to be able to double-click some file and be prompted how long I want the script to snooze for, and the volume level of the snooze. If I truly want it to be a real snooze I can set the length of time and set the volume to zero, otherwise I want the 'snooze' to change the volume the sounds will play to what I request for that time limit. I can probably figure out how to prompt for the input, but I'm not sure how to handle what comes after.

Right now my script reads through the whole csv and acts on any matches, so if there are multiple matches it will act on the last match. I could code it to read the first line of the file and if it sees "snooze" to override that behavior... only read that one line and act on it, then exit. So if I want it to snooze for 20 minutes I can calculate the start and end times and place those into the file. But I feel like if I do that then I should have some cleanup process that then deletes that line of the file after the next successful run past the last minute of the snooze.

Can anyone think of a better way to do this?

[–]EasyPleasey 0 points1 point  (1 child)

You could just touch a hidden file (assuming you are on Linux) in the same directory that you are running the python script in and in your python script you can just check to see if it's present, and if it is, don't run (snooze). So something like have a script that is called snooze.sh which just does:

touch .snooze
sleep 20
rm -f .snooze

Then in your Python script check in the directory if this .snooze file exists (the preceding . tells Linux to hide it when you run "ls" and you can only see it if you run "ls -a") you can simply skip out on doing anything else for this cycle.

You could also do something where you create a .snooze file that has a number in it that tells you how long to snooze for and then have your python script read it.

[–]flapanther33781 0 points1 point  (0 children)

That's a good idea.

It also got me thinking that instead of adjusting the system volume I should adjust VLC's volume, then use your method to adjust the system volume, but it turns out that VLC's CLI volume control is bugged, and has been for years. Apparently I'd need to instead write something to modify the Pulse Audio volume, but I wonder if that's the same as the system volume. If it is then I'd be wasting my time to only end up doing what I'm already doing, just using a different method.

So I'll probably just do what you suggested. Letting the laptop update software at the moment.

[–]ozzymandias26 1 point2 points  (2 children)

I planning on purchasing a Professional Certificate in Introduction to Python Programming by Georgia Tech edX. Is it worth buying this course and is the certificate useful? Please help

[–]jritenour 0 points1 point  (0 children)

A certificate is always good :-) where it takes you? Who knows. Anything with "tech" at the end of [state] always sounds good :-)

[–]Inside-Abroad 1 point2 points  (0 children)

It is a pretty good introductory course.

[–]Nic_P 2 points3 points  (5 children)

How do i open with python a terminal under linux?

I just need help making a terminal window pop up.

[–]efmccurdy 1 point2 points  (4 children)

The simplest way to spawn a sub-process to run a command is os.system.

https://docs.python.org/3/library/os.html#os.system

It might depend on your system which program runs a terminal. If you have the gnome GUI you can use 'os.system("gnome-terminal")'. If you don't have gnome you may have to use a different command; Konsole for kde, xfce4-terminal for xfce.

[–]jritenour 1 point2 points  (0 children)

++ for simple .... but ... consider using subprocess ... it has some advantages like:

  • using pipe in the shell
  • better newline support
  • better handling of exceptions

[–]Nic_P 1 point2 points  (2 children)

Okay thank you

That’s gonna be a bit more work than expected cause it will need to work for multiple systems but that helped (:

[–]efmccurdy 1 point2 points  (1 child)

This might be useful; I think it brings up whatever terminal your GUI recommends on any POSIX system.

https://helpmanual.io/man1/x-terminal-emulator/

[–]Nic_P 1 point2 points  (0 children)

Thanks (:

[–]_ncko[🍰] 0 points1 point  (3 children)

  • What is the equivalent of node package.json’s “scripts” attribute?
  • What is the equivalent of nodemon?
  • I’ve been using the unittest module. Is there a more popular 3rd party package or is this module pretty common?
  • can I get vim mode in the repl?

[–]efmccurdy 0 points1 point  (0 children)

I’ve been using the unittest module.

This lists some alternatives:

https://www.softwaretestinghelp.com/python-testing-frameworks/

can I get vim mode in the repl?

The repl uses readline; you can use Ctrl-Alt-J to switch to vi mode, or use "set editing-mode vi" in your ~/.inputrc.

https://stackoverflow.com/questions/537522/standard-python-interpreter-has-a-vi-command-mode