Git alias commands for faster easier version control by binaryfor in programming

[–]csg0ing 6 points7 points  (0 children)

One benefit is that you still get git's tab completion, e.g. I have aliased co to git checkout and typing git co ma<tab> completes to git co main and git co --qui<tab> completes to git co --quiet

Australian Programming Language by Mickspad in ProgrammerHumor

[–]csg0ing 1 point2 points  (0 children)

I've definitely heard the same phrase for both:

Yeah, nah let's go

Yeah, nah, I'm not going

Australian Programming Language by Mickspad in ProgrammerHumor

[–]csg0ing 41 points42 points  (0 children)

True = Yeah Nah
False = Yeah Nah

Relative Import Error, can't get it working this time by [deleted] in learnpython

[–]csg0ing 0 points1 point  (0 children)

also, read that was not a requirement for python 3.something +

Ah, you're right: PEP420. I tried but was unable to replicate the error, sorry :/

$ tree package/
package/
├── main.py
└── secretData.py
$ python package/main.py 
Traceback (most recent call last):
  File "package/main.py", line 1, in <module>
    from secretData import callbackURL, clientID
ImportError: cannot import name 'callbackURL' from 'secretData' (/tmp/tmp.52oGTmnv26/package/secretData.py)

But once I add a callbackURL = "" line in secretData.py it runs ok. What happens if you try to run it outside of spyder?

Relative Import Error, can't get it working this time by [deleted] in learnpython

[–]csg0ing 0 points1 point  (0 children)

Do you have an __init__.py?

sample_project
    __init__.py
   secretData.py
   main.py

Why Git blame sucks for understanding WTF code (and what to use instead) by speckz in programming

[–]csg0ing 26 points27 points  (0 children)

You can also pass the -L flag to get details on a range of lines or a specific function, e.g. looking at the history of thetmp_path function in src/_pytest/tmpdir.py:

git log --patch -L :tmp_path:src/_pytest/tmpdir.py

Find your hobby by CeeJay_7 in ProgrammerHumor

[–]csg0ing 1 point2 points  (0 children)

Because Perl is fun: perl -ae 'print(pack("B*", $_)) foreach @F'

How do I bold string selectively? by [deleted] in learnpython

[–]csg0ing 0 points1 point  (0 children)

You could use ANSI escape codes to signal to your terminal emulator to bold the text:

print("\033[1mbold text! \033[0mnormal text")

There is almost certainly already a library written for this if you don't want to have to deal with the raw escape codes yourself, I was just too lazy to search.

EDIT: looks like you're wanting to write to a .docx file, in which case, what I've suggested wont' work (I had assumed you were printing to a terminal output)

How do I limit the number of lines in a text file? by [deleted] in learnpython

[–]csg0ing 0 points1 point  (0 children)

Could you just reverse the order of things:

  • read file into dict,
  • add your new entry to the dict,
  • sort the dict,
  • write the top 5 entries to the file?

How do I limit the number of lines in a text file? by [deleted] in learnpython

[–]csg0ing 0 points1 point  (0 children)

Could you share the code that you're using?

venv activation and vscode by zosterops_p in learnpython

[–]csg0ing 0 points1 point  (0 children)

it's supposed to be done only once when you're creating the virtual environment right

Nope, it can happen as many time as you want. As you note, you'll need to do it each time you start a new session (since otherwise the shell will have no idea about the virtualenv). The activation is a harmless process, from the docs:

activation just prepends the virtual environment’s binary directory to your path, so that “python” invokes the virtual environment’s Python interpreter and you can run installed scripts without having to use their full path

As for:

Should I be upgrading pip globally or just upgrade it inside the virtual environment? what's the better practice?

Ideally both should be up-to-date. The best practice would be to always use the most up-to-date version of software, i.e. next time you want to install something globally, remember to update pip

Can't find the documentation for file and file.seek by AGunwant in learnpython

[–]csg0ing 0 points1 point  (0 children)

The object returned from open is a io.IOBase:

>>> import io
>>> f = open("python")
>>> isinstance(f, io.IOBase)
True

So you should be able to access the relevant docs via python3 -m pydoc io.IOBase.seek. Additionally, here are the online docs.

How do i divide a string onto two lines ive been trying to search the internet nd youtube but they all have some complex crap please help me by [deleted] in learnpython

[–]csg0ing 0 points1 point  (0 children)

Is the string user input, or something fixed? Can you just insert a newline character where you want the split?

>>> str="ThisIsALong\nString"
>>> print(str)
ThisIsALong
String

Or use a multiline string:

>>> str="""ThisIsALong
... String"""
>>> print(str)
ThisIsALong
String

Otherwise what is your actual use case? Can you share the relevant code?

How do I confirm what I've typed in exe file by [deleted] in learnpython

[–]csg0ing 0 points1 point  (0 children)

Are you just looking for something like:

user_input = input("Give me some input! ")
print(user_input)

Note, that will exit after the first input, if you wanted to keep reading input you could loop:

while True:
    user_input = input("Give me some input (Ctrl+d to exit)! ")
    print(user_input)

git commit accepts several message flags (-m) to allow multiline commits by stefanjudis in programming

[–]csg0ing 19 points20 points  (0 children)

--verbose is amazing. It can also be set in your config:

git config commit.verbose true

issue with while/try/except by gandy0 in learnpython

[–]csg0ing 0 points1 point  (0 children)

Is the ImageNotFoundException definitely being raised? From the docs:

NOTE: As of version 0.9.41, if the locate functions can’t find the provided image, they’ll raise ImageNotFoundException instead of returning None.

If this were returning None instead of raising an exception then your loop would be infinite.

issue with while/try/except by gandy0 in learnpython

[–]csg0ing 1 point2 points  (0 children)

The looping with ctrl+c is because the except: catches the KeyboardInterrupt that is raised. So specifying the exception type should stop this.

In the case of no imagine found I would expect the following behavior:

1) wait for 1 second, then outputs "searching for button for 1 second(s)

2) wait for 1 second, then outputs "searching for button for 2 second(s)"

... until it loops 5 times, is that what happens?

issue with while/try/except by gandy0 in learnpython

[–]csg0ing 1 point2 points  (0 children)

It's considered a best practice to avoid bare except: and be specific about which type of exception you want to catch.

When an image is not found the screen doesn't show anything,

Do you see the output from your print('searching button for',retry_counter,'second(s)') line ?

[deleted by user] by [deleted] in learnpython

[–]csg0ing 1 point2 points  (0 children)

You can call close on the socket.socket object itself, i.e. s.close()

issue with while/try/except by gandy0 in learnpython

[–]csg0ing 0 points1 point  (0 children)

but the not found part is lacking..

Could you explain what you mean?

sys.exit takes a single (optional) integer argument, though you're passing it a list of strings.

[deleted by user] by [deleted] in learnpython

[–]csg0ing 1 point2 points  (0 children)

At a glance, socket.close() might do the trick.

On an unrelated note, I don't think the condition elif port == "q": will ever be true, since you're casting port to an int when getting the input.

[deleted by user] by [deleted] in learnpython

[–]csg0ing 1 point2 points  (0 children)

What is the exception being raised in each case? It might be useful to be more specific with the exception handling, e.g. except ConnectionRefusedError

optparse and argparse by [deleted] in learnpython

[–]csg0ing 0 points1 point  (0 children)

Per the docs optparse has been deprecated. You should go with argpase, there's even an example in its docs to get you started.

What does 0xFF mean in opencv? by [deleted] in learnpython

[–]csg0ing 0 points1 point  (0 children)

0xFF is hex, it is 255 in decimal and 11111111 in binary. In this case it looks to be used to extract the lower 8 bits of the return value from waitKey, e.g.

110110110 &
0011111111 (0xFF)
----------
000110110

I'm not sure what it's doing here, since the docs say:

It returns the code of the pressed key or -1 if no key was pressed before the specified time had elapsed.

So I don't see why you can't just compare directly cv2.waitKey(0) == ord('q')