#๐ quick question
45 messages ยท Page 1 of 1 (latest)
@wet heron
Remember to:
- Ask your Python question, not if you can ask or if there's an expert who can help.
- Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
- Explain what you expect to happen and what actually happens.
:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.
price = price_tag.get_text(strip=True).replace('$', '').replace('\'', '') if price_tag else None
``` price normally looks like '$0.24. why isn't this working. $ gets removed fine but the ' stays
because you cant do .replace().replace(), it wont throw an error, but only the last replace will work
if the last replace will work then why is ' staying but $ getting replaced?
the output is '0.24
so the first replace works but the last doesn't
oh sorry i read that wrong, then the first one is the one that works, wasnt sure as i didnt see the second part at first
it's fine I get what u mean
is there any solution tho?
or should I just add another variable and then replace again?
waitt, i just tried it but removed the get text function cuz that isnt native, and it worked
price = "'$0.24"
price = price.replace('$', '').replace('\'', '') if price else None
print(price)
this worked
honestly it '$ are always the first 2 characters
you could get away with just slicing off the first 2 characters
oh yeah didn't even think of that
I need get tho
can you show the function and whats in it?
it's pretty big ngl. all I'm doing is scraping
I'll check rn 1 sec
take your time
dang
it's printing out as 0.24
so ig .replace().replace() does work
probably somewhere else is messing up then
it does i was the stupid one lol
this worked:
price = "'$0.24"
price = price.replace('$', '').replace('\'', '') if price else None
print(price)
this removed both correctly
yeah I don't think this is the problem
I'm getting this data and dumping to a spreadsheet
so probably somehow during the dump process the ' gets added
idk why I'm trying to find it rn
maybe add a replace at the end right before dumping to replace ' with " " and see if that works?
as i dont have most of ur code im not really sure sorry
I'll try that
you helped a ton
ima try and figure it out if I do I'll post the solution here
okay good luck!! <3
price = price_tag.get_text(strip=True).replace('$', '').replace('\'', '') if price_tag else None
price = float(price) if price else None
``` this ended up working. thanks for the help!
!close
This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.