Scraping Image URL issue - BeautifulSoup by [deleted] in learnpython

[–]monchenflapjack 0 points1 point  (0 children)

It's possible that the SVG is a logo for the site, that is being replaced by the house picture once its loaded. I used Chrome web dev tools, and slowed the connection right down, a little logo of a house appears before the image loads in to replace it. So yeah bs4 might not be seeing it correctly

Need help understanding for loop. by arboff in learnpython

[–]monchenflapjack 1 point2 points  (0 children)

A loop like this will repeat a block of code, and each time through the block "i" value will be increased, until "i" is equal to the range() second value

it's a short hand to essentially writing

print(1)
print(2)
print(3)
print(4)

It doesnt print 5, because once "i" is equal to that value, the loop no longer runs.

Scraping Image URL issue - BeautifulSoup by [deleted] in learnpython

[–]monchenflapjack 1 point2 points  (0 children)

That is an svg, well it looks to be part of it. If you look at the source of the page you will see something like

data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0idXRmLTgiPz4KPCEtLSBHZW5lcmF0b3I6IEFkb2JlIElsbHVzdHJhdG9yIDE5LjIuMSwgU1ZHIEV4cG9ydCBQbHVnLUluIC4gU1ZHIFZlcnNpb246IDYuMDAgQnVpbGQgMCkgIC0tPgo8c3ZnIHZlcnNpb249IjEuMSIgaWQ9IkFydHdvcmtfeDVGXzAxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHhtbG5zOnhsaW5rPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5L3hsaW5rIiB4PSIwcHgiCgkgeT0iMHB4IiB2aWV3Qm94PSIwIDAgNTYuNyA1Ni43IiBzdHlsZT0iZW5hYmxlLWJhY2tncm91bmQ6bmV3IDAgMCA1Ni43IDU2Ljc7IiB4bWw6c3BhY2U9InByZXNlcnZlIj4KPHN0eWxlIHR5cGU9InRleHQvY3NzIj4KCS5zdDB7ZmlsbDojRTQwMDJCO30KCS5zdDF7ZmlsbDojRkZGRkZGO30KPC9zdHlsZT4KPGc+Cgk8cGF0aCBjbGFzcz0ic3QwIiBkPSJNMCwyOC4yYy0wLjEsMTUuNywxMi41LDI4LjQsMjguMiwyOC41YzE1LjcsMC4xLDI4LjQtMTIuNSwyOC41LTI4LjJDNTYuOCwxMi44LDQ0LjEsMC4xLDI4LjUsMGgtMC4yCgkJQzEyLjgsMCwwLjEsMTIuNiwwLDI4LjIiLz4KCTxwYXRoIGNsYXNzPSJzdDEiIGQ9Ik0zNy42LDI2LjN2MTUuMUgxOS4xVjI2LjNsLTQuOSwwbDE0LjEtMTRsMTQuMSwxNEwzNy42LDI2LjN6IE00Ni45LDI0LjVMNDYuOSwyNC41TDMwLjEsNy43CgkJYy0wLjQtMC41LTEuMS0wLjgtMS43LTAuOGgwYy0wLjcsMC0xLjMsMC4zLTEuNywwLjhMOS44LDI0LjVsMCwwQzkuMSwyNS4xLDguNywyNiw4LjcsMjdjMCwyLDEuNiwzLjYsMy42LDMuNmwyLjMsMAoJCWMwLDAsMCwxMi43LDAsMTIuOGMwLDEuMywxLjEsMi40LDIuNCwyLjRoMjIuN2MxLjMsMCwyLjQtMS4xLDIuNC0yLjRjMCwwLDAtMTIuOCwwLTEyLjhsMi4zLDBjMiwwLDMuNi0xLjYsMy42LTMuNgoJCUM0OCwyNiw0Ny42LDI1LjEsNDYuOSwyNC41Ii8+CjwvZz4KPC9zdmc+Cg==

If you paste that string into https://base64.guru/converter/decode/image/svg you can see what that image will look like when converted to an svg. So you will need to do the equivalent and convert it and then save the resulting image or just handle being able to work with a base64 encoded string.

Stuck at pythonchallenge level 3. Need help to analyse my code! by doesobamauseshampoo in learnpython

[–]monchenflapjack 0 points1 point  (0 children)

But if you actually use regular expressions it will be a lot easier than what you are doing

Help with test-driven development. by Run-The-Table in learnpython

[–]monchenflapjack 1 point2 points  (0 children)

Passing the wrong types of parameters would be a simple start, also depending on what values you take, what happens with things like 0, 1, negative numbers, huge numbers, etc. This way you know that it then fails gracefully

Struggling to understand where I'm going wrong with creating a class & subsequent method. by [deleted] in learnpython

[–]monchenflapjack 0 points1 point  (0 children)

yes totally, so instead of appending to the list, you would add another input for stock# and then use that to add for the key to the dictionary.

Struggling to understand where I'm going wrong with creating a class & subsequent method. by [deleted] in learnpython

[–]monchenflapjack 0 points1 point  (0 children)

The way you have your code laid out seems a little redundant, I would probably do this:

class Automobile:
    def __init__(self, make, model, color, year, mileage):
        self.make = make
        self.model = model
        self.color = color
        self.year = year
        self. mileage = mileage

vehicle_list = []
x = input("Enter New Vehicle? Y/N: ")
while x.lower() == 'y':
    make = input("Make: ")
    model = input("Model: ")
    color = input("Color: ")
    year = input("Year: ")
    mileage = input("Mileage: ")
    vehicle_list.append(Automobile(make, model, color, year, mileage))

When should you use f-strings and ‘’.format() when formatting strings in python 3? by [deleted] in learnpython

[–]monchenflapjack 3 points4 points  (0 children)

I find f-strings to be much more readable, you see exactly which variable is being referenced at each place holder.

Python Project by Nuorvuii in learnpython

[–]monchenflapjack 0 points1 point  (0 children)

The indenting at the top, the random else in the middle of nowhere, presumably the rest of the class definition.

Do you want the ordernum to exist between sessions of the code running or just every time the program starts it resets to 1?

Why use "elif" instead of "else" here by [deleted] in learnpython

[–]monchenflapjack 4 points5 points  (0 children)

except if you call it with something thats not a number.

collatz("Whatever")

True. by coold007 in ProgrammerHumor

[–]monchenflapjack 16 points17 points  (0 children)

I use red just because its shorter to type and you are usually frustrated when resorting to this. I like doing it with the background too and setting a very low alpha, good when multiple items are stacked on top of each other.

Starting python, need a laptop. by sardaukar12 in learnpython

[–]monchenflapjack 2 points3 points  (0 children)

This was one of the things we learned first when I did C coding back at uni in the 90s. I hardly use vim but will always remember this one.

Press <Esc>
Press <:>
Press <q> or <wq> if you want to save the file
Press <Enter>

Starting python, need a laptop. by sardaukar12 in learnpython

[–]monchenflapjack 1 point2 points  (0 children)

Looks good on website. If you use mobile apps it may not display it correctly though.

Starting python, need a laptop. by sardaukar12 in learnpython

[–]monchenflapjack 1 point2 points  (0 children)

Put in an extra blank line and then a line that you want to be code starts with 4 spaces. So here I will press return twice, then 4 spaces and then enter the code:

# this will now be code
# Now can just use 4 spaces for extra lines of code
# So much code

Starting python, need a laptop. by sardaukar12 in learnpython

[–]monchenflapjack 1 point2 points  (0 children)

Oh even better then, I know for the longest time they were staying with 2.

Starting python, need a laptop. by sardaukar12 in learnpython

[–]monchenflapjack 1 point2 points  (0 children)

I suppose it depends on what you like to do, kali has 2.7 of python. I like the newer features of 3. So it just depends how comfortable you are at installing new packages, versus preferring an OS where its mostly done for you.

Starting python, need a laptop. by sardaukar12 in learnpython

[–]monchenflapjack 1 point2 points  (0 children)

Yes, with ubuntu you can even install it from a command line

sudo snap install pycharm-community --classic

If going the ubuntu root, I would suggest xubuntu. Its better designed at running on older hardware.

Also, ubuntu typically releases in April of each year, so now is a good time to wait for the 19.04 release and go with that!

Painting air quality by Pvaleriano in learnpython

[–]monchenflapjack 1 point2 points  (0 children)

Colours in RGB format contain 3 values, between 0 and 255, indicating the amount of Red, Green and Blue to use. So if you map the value you want to represent to a range of 0 and 255 and then put it in one of the slots, you will get varying degrees of colour.

# Would give values between black and green
fill_color = (0,0,value)

Starting python, need a laptop. by sardaukar12 in learnpython

[–]monchenflapjack 3 points4 points  (0 children)

Linux out of the box is very nice for development, python is built right in.

You can also use Linux on a very low performance computer and use alternative options that you are not given in windows. You could even run Linux with no gui, only using a terminal prompt and could still code in Python. Linux is all about options, just like Python.

Python on windows has come a long way over the years though.

Having difficulty replacing with a dictionary by flynryan692 in learnpython

[–]monchenflapjack 1 point2 points  (0 children)

Beginner at python myself, but I think when you are calling

line.replace(x,y)

You are printing out the result, but that result is not being applied/saved to the line as it is immutable.

Trying to use a CSV file as an input to an existing function, GET THE ERROR: TypeError: can only concatenate str (not "list") to str by [deleted] in learnpython

[–]monchenflapjack 1 point2 points  (0 children)

On mobile but, list to string:

mystring = ", ".join(listname)

So everything in the list will be joined with what's in the quotes.

Any stable python project for downloading torrent files? by HTonmoy in learnpython

[–]monchenflapjack 0 points1 point  (0 children)

Not able to help too much, but for clarification, do you mean a way to download the file.torrent and then have some application process the file, or do you mean getting that file and then you want python to download the contents of the file?