#๐Ÿ”’ quick question

45 messages ยท Page 1 of 1 (latest)

wet heron
#

hi so

weak girderBOT
#

@wet heron

Python help channel opened

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.

wet heron
#
        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
pearl bane
#

because you cant do .replace().replace(), it wont throw an error, but only the last replace will work

wet heron
#

the output is '0.24

#

so the first replace works but the last doesn't

pearl bane
wet heron
#

it's fine I get what u mean

#

is there any solution tho?

#

or should I just add another variable and then replace again?

pearl bane
#

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

wet heron
pearl bane
wet heron
#

it's pretty big ngl. all I'm doing is scraping

pearl bane
#

are you sure that its returning '$0.24

#

you could print what its returning

wet heron
#

I'll check rn 1 sec

pearl bane
#

take your time

wet heron
#

dang

#

it's printing out as 0.24

#

so ig .replace().replace() does work

#

probably somewhere else is messing up then

pearl bane
#

this worked:

price =  "'$0.24"
price = price.replace('$', '').replace('\'', '') if price else None
print(price)
#

this removed both correctly

wet heron
#

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

pearl bane
#

as i dont have most of ur code im not really sure sorry

wet heron
#

ima try and figure it out if I do I'll post the solution here

pearl bane
wet heron
# pearl bane 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

weak girderBOT
#
Python help channel closed

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.