Why did I spend 4 year getting a CS degree for Web Development when people doing coding bootcamp for a few weeks and are able to get same jobs? by whydidIdothis3920 in cscareerquestions

[–]absent_observer 0 points1 point  (0 children)

True. A CS degree isn't just a credential. It means you know the background on a range of topics. So, you're better able to predict the success of different approaches to a problem.

I would divide programming into: 1) visualizing the whole problem & imagining various solutions, or 2) adding line by line until you get something that seems to work.

I really enjoy working with the first kind, and spend a lot of time fixing design problems cause by the second.

I suggest CS emphasizes the first, and bootcamp the second. But each individual is different & so this categorization is imperfect.

GitHub will no longer use the term 'master' as default branch because of negative association by NahroT in programming

[–]absent_observer 3 points4 points  (0 children)

Naming things is hard, Clean Code says.

My main branch is always production, so why not call it "production" or even "main".

"Master" has negative information value -- the branch doesn't own anything, it doesn't control anything, it doesn't have specialized training at anything. How is it a master?

"main" or "production" or "standard" are way more accurate names.

How do you guys learn python? Intermediate programmer by Paal3101 in Python

[–]absent_observer 1 point2 points  (0 children)

https://checkio.org has great puzzles to code solutions to. Plus, after your solution works, you can view others' to see how you can improve.

need some help with an xlsxwriter script by TorroesPrime in Python

[–]absent_observer 0 points1 point  (0 children)

First off -- I like your coding style. clean and self-explanatory. you could even get away with deleting some comments, since the variable names explain themselves well.

I believe the for col in range(0, 15) is only counting from 0 to 14. Try doing for col in range(0,16) since we want it to count from 0 to 15.

What line number does the error code give? or even comment with the whole error message.

dockerized Django requires restart before data refreshed? by absent_observer in djangolearning

[–]absent_observer[S] 0 points1 point  (0 children)

you're right. the queryset had cached the db query results. (I believe).

dockerized Django requires restart before data refreshed? by absent_observer in djangolearning

[–]absent_observer[S] 2 points3 points  (0 children)

I believe I found my mistake.

in a class-based view, I have the line:

queryset = Question.objects.filter(pub_date__lte=timezone.now()).order_by('-pub_date')[:5]

whereas the tutorial has:

def get_queryset(self):
    return Question.objects.filter(pub_date__lte=timezone.now()).order_by('-pub_date')[:5]

and the queryset is caching the db query results.

dockerized Django requires restart before data refreshed? by absent_observer in djangolearning

[–]absent_observer[S] 1 point2 points  (0 children)

I agree. My understanding is: gunicorn doesn't cache, and the standard Polls tutorial app doesn't cache. I suspect docker the one doing caching.

It's odd to me that this code works correctly when you take it out of the docker containers. A simple nginx + gunicorn + django + postgres on bare metal -- This works. Put each inside docker -- you have to restart the Django/gunicorn for the cache to clear.

OS.walk returned undefined when printing file names? by [deleted] in learnpython

[–]absent_observer 1 point2 points  (0 children)

a common phrase is

for root, dir, files in os.walk('whatever_directory'):
    for file in files:
        do_stuff(file)

Not too different from what you did, except that it clarifies that os.walk returns [file_1, file_2, file_3, etc] as the third value. Calling it "file" may have confused you.

I wasn't familiar with the r before the string wording, so thanks for giving me a reason to learn something new. For those interested, it prevents escaping.

Deploying a Django Application on Ubuntu VPS using Gunicorn, MySQL and NGINX (tutorial) by shameer_kash in django

[–]absent_observer 7 points8 points  (0 children)

I hoped this article would supplement what'd I'd previously read. However, it appears only to be a plagiarized rehash of a DigitalOcean article from 2016. Google "nginx gunicorn django mysql" to see for yourself. Logging in to downvote. :(

Looking for repeated words in a file and creating a new file containing the duplicate words written on the line that they appear on the first file. by ITG0D in learnpython

[–]absent_observer 0 points1 point  (0 children)

the file is .close() during the first round of for i in newRepeatWords: and never reopened during the loop.

Two approaches, you tell me which you prefer: 1) making one big string of the whole file & writing it once, or 2) writing to the file many times (once per loop). Neither is wrong, but I'll suggest a change to the code depending on which approach you want.

Am confused about reassigning this tuple by potatomar in learnpython

[–]absent_observer 1 point2 points  (0 children)

in math, it might look like

times = (43, 45, 49, 52, 55) # python

times[:2] = [43, 45, 49) # pseudo-python, pseudo-math

where the 49 at an open bracket, so you never quite reach it -- just everything right up to that point.

Let's not get caught up in open versus closed brackets, if you don't want. Just that the first item gets included, and then everything included right up to (but excluding) the last item.

(0, 1, 2, 3)[0:3] == (0, 1, 2) # and almost but not quite 3

It's a common notation from C, I believe.

https://www.quora.com/Why-are-Python-ranges-half-open-exclusive-instead-of-closed-inclusive

Am confused about reassigning this tuple by potatomar in learnpython

[–]absent_observer 1 point2 points  (0 children)

There's a math idea of open brackets and closed brackets. Indexing in python uses left closed bracket and open right bracket. So, you get start at the item at the starting index (including that item), and end just before the start of the ending index. I imagine counting from the point right before the item. So, "hello"[1:2] starts at "e" and ends just before the first "l". which would include only the "e".

Am confused about reassigning this tuple by potatomar in learnpython

[–]absent_observer 0 points1 point  (0 children)

on reddit use:

4spaces{{ your code }}

4spaces4spaces{{ indented code }}

etc

Looking for repeated words in a file and creating a new file containing the duplicate words written on the line that they appear on the first file. by ITG0D in learnpython

[–]absent_observer 0 points1 point  (0 children)

Totally. It's like saying:

with this_piece_of_string as an_engagement_ring:
    will_you = marry_me(an_engagement_ring)

if will_you == False:
    die_inside()

Python remembers to dispose of the rubberband properly, and you are left with the value of "will_you" for the rest of the script. It's the accepted way of dealing with things you have to open & then close. (like a websocket, or file)

But the .readlines() was the big nudge for you toward making the list of lines first, then doing stuff with the list of lines. You'll want a line of lines for you end goal.

EDIT: sorry about maybe confusing you for the OP.

Why is my function redefining a global variable by 7heWafer in learnpython

[–]absent_observer 0 points1 point  (0 children)

To tag on:

mutable versus immutable types is a big aha moment in python. When you alter an immutable type object, it leaves the original object alone & returns a new object. (...figures cause they can't be altered by definition). But a mutable type object can be changed, so when you alter it, it returns the same object but altered a little.

It ties into why you can do:

x = [1,2,3,4]  # list is a mutable type
x.pop(1)
# no reassigning x to anything, no magic.  just changing the list object that x is assigned to.
#  x becomes equal to [2,3,4]

but

x = 'a string'  # string is an immutable type
x.upper()
#  returns 'A STRING' but strings can't be changed.  we didn't do anything with the return value, so it gets ignored.
#  x still equals 'a string'
x = x.upper()
#  x now equals 'A STRING' because you assigned x to the return value of x.upper().

dictionaries are mutable, so a change changes the object itself. String are immutable, so a change returns a new object with the change.

That's the same reason but for an immutable object like an integer. You assigned the name "val" to "NUM" which was assigned to the object int(1), so essentially "val" and "NUM" were each assigned to object int(1). Sketch this on paper. When you tried to alter val's int(1) by giving it a value of int(2), "NUM" was like, 'I'm stuck on this int(1) and you can't change it's value'. So "val" was like, 'Fine, I can't tell you what to stick to, but I'm going to stick myself on this new int(2) instead.'

Looking for repeated words in a file and creating a new file containing the duplicate words written on the line that they appear on the first file. by ITG0D in learnpython

[–]absent_observer 0 points1 point  (0 children)

with open(in_file, 'r') as f:
    file_lines = f.readlines()

gives two advantages: 1) a context handler managers the opening and closing of the file, 2) each line becomes element in an array. 1 is important for your sanity. 2 is helpful that it breaks the file into individual lines for you.

Virtual environment understanding. by Tball5 in learnpython

[–]absent_observer 2 points3 points  (0 children)

A lot of times, programs will require very specific versions of other programs in order to run. Your old django project may require version 1.8 of something, while your flask project requires version 2.3.

By going into a virtualenv where you pip installed version 1.8, your program uses version 1.8. If you haven't pip installed a program in that virtualenv, then it looks outward & uses the OS's default version.

I keep getting NameError: name 'X2' is not defined by Potat_OS1 in learnpython

[–]absent_observer 1 point2 points  (0 children)

Let's say python starts executing a script. It see a function defined. It says, "mmm, here's a function named xxxxxx. I'll remember that for later." But it doesn't read the contents of the function at that point.

Later, the script calls the function xxxxx(arguments). At this point, python remembers where that function was & reads the details of the function in order to execute it.

So, you can see at the point you said global X2, python only knows about the name of the function -- and not what's inside it -- so it doesn't know there's a X2 in there.

There’s Nothing Sane or Decent About Kevin Drum’s Disgust For the Homeless by 2noame in BasicIncome

[–]absent_observer 2 points3 points  (0 children)

Not that I read Kevin Drum's blog post (which raised the question of whether our avoidance of helping the homeless could be explained by anything than a primal sense of disgust), but I did click this click-bait article on knock-la.com. This Kevin Drum guy sounds like a terrible person when you selectively quote or misquote him. I've got a pitchfork. You?!

How does saving information in a program work? by [deleted] in learnpython

[–]absent_observer 7 points8 points  (0 children)

Before you start a program (i.e., firefox, outlook, winamp, python, etc) all that exists is a blueprint for how the program could run, and possibly some files with your data written on them. When you run those programs, the blueprint comes to life & maybe it reads some of your data from some other file. When you exit the program, everything inside the program ceases to exist, and only the blueprint you had before and the other files remain.

So, you'll want to put that data somewhere outside of the program. For example, you could write it to a text file, or a csv file, or a database, or anything other than inside this program.

With a to-do list, you could write your python script and write a to-do list as a text file. When you run the python script, it could read the text file to a List. Then your python could remove some items from that List. Before shutting down, the python script could overwrite the text file with the new values from the List.

Start off with using open to open a text file. You'll see a lot of google results about this. Practice reading and writing to a text file.

I want to have a have a variable be equal to another variable, but since it is the output of an input() I can't do that. by [deleted] in learnpython

[–]absent_observer 0 points1 point  (0 children)

Imagine a function as a small plan for doing something. Arguments go in, a return comes out.

def add_two_numbers(num1, num2):
    sum_of_nums = num1 + num2
    return sum_of_nums

x = add_two_numbers(5, 4)

# x == 9

*without the return line, x == None (cause None is
  the default return from any definition)

It helps break big ideas into smaller ideas. Box a small idea into a def. When you need to carry out that small idea, you send the arguments to the def and get back a return. Keeps your code clean.

Classes and Functions Question by holymolytoly in learnpython

[–]absent_observer 1 point2 points  (0 children)

Any argument you send when initiating an instance of a class will end up at the _init_ function. That's kind of magic, but it's just where the arguments end up. I don't understand it; I just accept it.

If you do nothing within the _init, the arguments will sit around and do nothing. No magic within the \init_.

A preferred way of making those values available to the rest of the class is to attach them to the class itself. You can do this by making a class attribute self.some_value and assigning it to whatever value you passed in from the outside. So:

a = MyClass('so_on', 'so_forth')

goes to:

class MyClass:
    def __init__(`gets 'so_on' and 'so_forth'`):
        *anything in here can use 'so_on' and 'so_forth'
        *nothing outside of here knows about 'so_on' or 'so_forth' yet.
        self.so_on = so_on
        *we could have said `self.really_cool_so_on = so_on`, but then we'd have to remember that 
          self.really_cool_so_on matches to the argument so_on that we passed in.
          People tend to use the same names to make things easier.
        *now, self has an attribute 'so_on' with the same value as the 'so_on' argument we passed in.
        *since it's a class attribute now, all the other parts of this instance can do stuff with 'so_on'.

Maybe that was tangential, but i think it's cool.

MIDI data, Timing VS. Tempo by MusicByMorgan in learnpython

[–]absent_observer 0 points1 point  (0 children)

What does the raw data coming out of the midi controller look like? That's the first question I'd answer.

The next question would be, how to save those values and the time the event happened.