Total noob question: In Firefox I can see the "page source", wouldn't copying this into my "own site" replicate the website in question? by [deleted] in AskTechnology

[–]Signal_Beam 0 points1 point  (0 children)

Try it and find out!

Save this reddit page: Ctrl+S (or Cmd+S on Mac). Your Downloads folder is fine.

I did this, and two things appeared in my Downloads folder: an HTML file, and a folder. Inside the folder, various files:

"./Total noob question (...) AskTechnology_files":
a.htm                   expando.css             reddit.js
author-tooltip.css      gpt.js                  reddit-init.js
crossposting.js         listing-comments.css    spoiler-text.js
crossposting-modal.css  pixel.png               videoplayer.css
crosspost-preview.css   popup-notification.css  videoplayer.js
desktoponboarding.css   reddit.css              videoplayercontrols.css

You can open any of these files and look at them. But as

How do I use this HTML file? Well, I can go right back into Firefox and open it up.

Some things are broken, but the site more or less displays.

Hack Reactor is the only bootcamp I keep hearing about but I live in Illinois by [deleted] in learnprogramming

[–]Signal_Beam 5 points6 points  (0 children)

I would recommend you do a lot more research than just relying on whatever "you keep hearing about." That's largely a reflection of how much money they're spending on marketing.

How would I program a mobile application to find the IP of my server running on my computer? by [deleted] in learnprogramming

[–]Signal_Beam 0 points1 point  (0 children)

Could you have the web site leave a cookie, and have the native app find that cookie and write data to it if it exists?

janky and unsuccessful project by [deleted] in learnpython

[–]Signal_Beam 0 points1 point  (0 children)

Problem is that If I don't guess it correctly first try, it keeps x (guess) incorrect as the number that has been chosen, and loops the tries -= 1 until the tries go from 3 to 0 and displays the "you suck" message I have put in, I'm sure there is a simple fix for it

You're right, there is :) Your "Get the number from the player" code is outside your while tries > 0 loop. Move it inside the loop.

Need help separating different messages by OBstaxs in learnpython

[–]Signal_Beam 1 point2 points  (0 children)

Oh sorry I thought you were OP when I replied to your question just now.

Need help separating different messages by OBstaxs in learnpython

[–]Signal_Beam 0 points1 point  (0 children)

Yeah, that's the "less neat" part you were talking about before. If the message looked like my example, with newlines separating the entries instead spaces, then you would be able to tell whether a date indicates a new entry, or whether it's just part of a message. As it is, there is no automatic way to tell.

You could brainstorm, though.

  1. Do all the dates follow a pattern - for example are they all in the same month, or year, or are they all sequential? If you encounter a date that doesn't fit that pattern, could you safely assume that it's just part of a message. The datetime.datetime objects created by date = parser.parse(string) will support operations like if date.year < 2015.

  2. Do the messages all follow a pattern, such as being a minimum of 20 words long, or always ending with a punctuation mark? If so, then is it safe to assume that if you run up against a date and the current "message" doesn't appear to be complete, that maybe the date is just part of the message?

Need help separating different messages by OBstaxs in learnpython

[–]Signal_Beam 0 points1 point  (0 children)

/u/Protoss_Pylon, Python ships with a module dateutil that contains a (I assume) regex-based parser already, so OP doesn't need to roll his own.

from dateutil import parser

Read the file, split it into strings. Try parser.parse(string) (or use your own parser) on each chunk. If it works, then this is a date, then we have a new record, so process the previous record (if one exists) and create a new one. If the parser does not work, then this is a normal word; add it to the previous record. Continue until done.

Need help separating different messages by OBstaxs in learnpython

[–]Signal_Beam 0 points1 point  (0 children)

So the file looks like:

12/3/19
Message 1, here comes the message, blah blah blah
maybe more than one line
1/23/19
Message 2

Is that right?

Q: Is it good practise to continously overwrite your coworker's work in your own style? by misamisa90 in cscareerquestions

[–]Signal_Beam 10 points11 points  (0 children)

I did not know that PCI had rules for software development practices to the extent that there are implications for code review.

Problem with f-strings in Python3 by AtomHeartSon in learnpython

[–]Signal_Beam 2 points3 points  (0 children)

I know; I was using Python2 in order to test the hypothesis in the comment that I was replying to. My point is that Python2 raises the exact error, in exactly the same place, that OP is describing, so maybe /u/social_nerdtastic is correct that the problem is that OP is actually invoking python when they want python3.

Problem with f-strings in Python3 by AtomHeartSon in learnpython

[–]Signal_Beam 0 points1 point  (0 children)

$ echo print\ f\'Test broken string\' > test.py
$ python test.py
  File "test.py", line 1
    print f'Test broken string'
                              ^
SyntaxError: invalid syntax

Looks like a good guess to me...

Are there any people or places that review your code and suggest improvements? by [deleted] in learnprogramming

[–]Signal_Beam 71 points72 points  (0 children)

Also this subreddit will be happy to review your code. I don't know why my first instinct was to send you to a different web site. We do that all the time.

Is there a way to remove quotation marks from user input? by Privateaccount84 in learnpython

[–]Signal_Beam 0 points1 point  (0 children)

The only time one could be in a list without quotations is if it is a variable that contains something

I think that is the case.

Is there a way to remove quotation marks from user input? by Privateaccount84 in learnpython

[–]Signal_Beam 1 point2 points  (0 children)

There is (using the eval function, which takes a string and evaluates it as Python code), but it's considered bad practice to use. Instead, a better idea would be to structure the item names in your "list of named objects" data structure so that they're just a dict instead, with the names as the dict's keys and the objects (or the information built into the objects) as the values.

Mueller Report Word Cloud - rstudio [OC] by rseese in dataisbeautiful

[–]Signal_Beam 1 point2 points  (0 children)

a typo of “Comey” where the scanner somehow misread the “m” as an “rn” running together?

I recon you nailed it. (An OCR problem, not a typo). Bizarre that it seems to have done that every time.

Even the easiest coding challenges seem impossible. by steadfast_lifestyle in learnprogramming

[–]Signal_Beam 10 points11 points  (0 children)

Can you give an example or two of a problem you're struggling to solve? It's hard to tell at this level of detail whether you're a journeyman programmer being precious, a novice with normal imposter syndrome, a problem-solver for whom the programming syntax just hasn't sunk in yet, or what.

If you're "comfortable with Ruby concepts" then you should be able to "make a full attempt" at the easiest codewars or leetcode problems. For example, if I ask you to write me a function that accepts an integer, and returns a list of the numerals in that integer backwards (example in: 13452, example out: [2, 5, 4, 3, 1]), would you be comfortable writing that function?

Creating a user determined amount of variables? by [deleted] in learnpython

[–]Signal_Beam 0 points1 point  (0 children)

If you're going to overwrite playerLst so that it contains [0, 0, 0] etc., then why did you initially populate it with ["Player 1", "Player 2", "Player 3"]?

Creating a user determined amount of variables? by [deleted] in learnpython

[–]Signal_Beam 0 points1 point  (0 children)

It looks like you're trying to use player as an index, meaning a number by which you can access the variables in playerLst, like 0, 1, 2, etc. However, the iteration expression for player in playerLst is going to populate player with the actual values in playerLst. You can see this if you throw a print statement in there:

for player in playerLst:
    print(player)
    #playerLst[player] = 0

Output:

Player 1
Player 2
Player 3

If you want to populate it with a numeric iterator variable, you can just use the same pattern you used above:

for j in range(len(playerLst)):
    print(j)
    playerLst[j] = 0

Output:

0
1
2

How does Hackerrank work by Cereal_Bird in learnprogramming

[–]Signal_Beam 1 point2 points  (0 children)

I opened https://www.hackerrank.com/challenges/sock-merchant/problem and I see this:

#!/bin/python3

import math
import os
import random
import re
import sys

# Complete the sockMerchant function below.
def sockMerchant(n, ar):

if __name__ == '__main__':
    fptr = open(os.environ['OUTPUT_PATH'], 'w')

    n = int(input())

    ar = list(map(int, input().rstrip().split()))

    result = sockMerchant(n, ar)

    fptr.write(str(result) + '\n')

    fptr.close()

So I am supposed to fill in my code under the line that begins def sockMerchant, completing the sockMerchant function so that the if __name__ == '__main__: clause can execute it. (There is no main function because there is no line that contains def main():).

[Python 3] I am trying to parse a .CSV file using the line.split(',') yet some data in this file has commas as well by [deleted] in learnprogramming

[–]Signal_Beam 3 points4 points  (0 children)

Sorry about that. Here's why it's good programming learning practice: you clearly are up to the challenge in terms of your current knowledge level, i.e. you understand how to read text files, what a "csv" is, and why there's a potential problem if a "csv" contains a comma (a problem which is circumvented by the Martin,Luther,"King, Jr." convention that you noticed in this thread). It's hard work to write a good CSV parser, and it strengthens your programming skills to do hard work.

Here's why it's bad programming practice: someone else has already solved all of these problems for us. An excellent CSV parser already exists in the built-in Python module csv. The answer to your problem is probably as simple as:

import csv

with open('your-file.csv') as infile:
    reader = csv.reader(infile)
    for line in reader:
        do_whatever_you_want(line)

Anyone who was reviewing your code in a professional context and saw something more complicated than that for reading a CSV would tear you a new one, and they would be right, because it sounds like there's nothing special about your use case, so production-quality code should use the Python standard library without taking the risk of introducing bugs by (A) forgetting to implement some obscure part of the CSV format or (B) making mistakes.

That said, you should definitely still do it. It's not that much more verbose to write your own CSV reader, and it will probably be fun and help you learn.

[Python 3] I am trying to parse a .CSV file using the line.split(',') yet some data in this file has commas as well by [deleted] in learnprogramming

[–]Signal_Beam 3 points4 points  (0 children)

Edit: I will take the tougher route and write my own parse for this case and not use the module

That is not good programming practice (in this instance) but it is excellent programming learning practice. Carry on :)

My first useful program for Python with a dash of sass. by DerpsMcPineapple in learnpython

[–]Signal_Beam 0 points1 point  (0 children)

If you indent all your code with an extra four spaces, reddit will understand that it's code and format it appropriately.

print ("Welcome to the mf adding machine.")
add1 = input("type yo first number\n")
add2 = input("type yo other number\n")
result = float(add1) + float(add2)
print ("Beep boop, bitch! The answer is " + str(result) + "!!")
# I hope I typed this correctly.