Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 1 year ago.
Improve this question
I have a problem. I want to make a login and password in an impromptu program. How do I store the text value of a variable. I ask questions do not ask me I am a Russian-speaking. Piece of code:
import os
print("login:")
logg=input(">")
print("password:")
pasw=input(">")
if logg==rlogg or pasw==rpasw:
<<body programm>>
else:
<<body programm>>
I need to assign the rlogg and rpasw variables to their values in the file. And after that, if the values that were entered in logg and pasw are equal to rlogg and rpasw, then the program continues, if not, then the program is restarted.
your question was not very clear, but this example can help you
account.txt >> username:passowrd
Save the username and password in the account.txt file
#To store information in a file
def save(username,password):
with open("./account.txt","w") as file:
file.write(f"{username}:{password}")
def login(username,password):
with open("./account.txt","r") as file:
user,passwd = file.read().split(":")
if username==user and password==passwd:
return True
return False
print("login:")
logg=input(">")
print("password:")
pasw=input(">")
if login(logg,pasw):
print("Login successfully")
else:
print("Failed login")
Related
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 9 months ago.
Improve this question
Input: abc#xyz.com
Output: xyz
my code is below
email = "123#helloworld.com"
new_email = email.split('#')[1]
domain = new_email.split('.')[0]
Please help me with other methods to get the part of it?
UPDATE (Based on a comment, see below)
If you have input like 123#helloworld.python.com or 123#helloworld.yahoo. And you want to extract only helloworld. You can use
result = re.search(r'#([^\.]+)\.', email).group(1)
BEFORE UPDATE
You can use re module.
import re
email = email = '123#helloworld.com'
result = re.search(r'#(.+)\.com$', email)
if result:
result = result.group(1)
print(result)
Output:
helloworld
If you are sure that you will always have something in between # and .com. You can remove if statement.
import re
email = email = '123#helloworld.com'
result = re.search(r'#(.+)\.com$', email).group(1)
print(result)
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 12 months ago.
Improve this question
I am following an article about image caption transformer model in tensor flow python. When I try to run the following code it does not show the data when I use the head function.
file = open(dir_Flickr_text,'r')
text = file.read()
file.close()
datatxt = []
for line in text.split('\n'):
col = line.split('\t')
if len(col) == 1:
continue
w = col[0].split("#")
datatxt.append(w + [col[1].lower()])
data = pd.DataFrame(datatxt,columns["filename","index","caption"])
data = data.reindex(columns =. ['index','filename','caption'])
data = data[data.filename !='2258277193_586949ec62.jpg.1']
uni_filenames = np.unique(data.filename.values)
data.head()
After running this I see three columns (index, filename , caption) with no data at all. While the real file contains enough data and the in the article they display the data too.
It doesn't show any data because the dataframe is empty, probably because datatext is empty. Try using a print() statement before data=pd.DataFrame(... to see what is going on.
It is hard for us to debug without the dataset.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 2 years ago.
Improve this question
I want to print firstname of employees who have both work number and mobile number. Below is my json body. I am facing difficulty in getting inside phoneNumbers attribute. My final output should be: "Adhi as Adhi has both work and mobile numbers".
I am not able to iterate the inner dictionary of phoneNumbers attribute.Can you please help me on this.
This is my python code
for i in Data['users']:
for j in i['phoneNumbers']:
for i in range(len(j)):
if j['type']=="work" and j['type']=="mobile":
print("Firstname",i['firstName'])
You can loop over the users and check if the work and mobile number are present:
for user in Data['users']:
has_mobile_number = False
has_work_number = False
for phonenumber in user['phoneNumbers']:
if phonenumber['type'] == 'work':
has_work_number = True
if phonenumber['type'] == 'mobile':
has_mobile_number = True
if has_work_number and has_mobile_number:
print('Firstname', user['firstName'])
Also, I recommend not using i and j when not talking about indexes. In you code, i is a dict representing a user and j is a dict representing a phone. I replaced them with user and phonenumber for more clarity in the code above.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 3 years ago.
Improve this question
while True:
if bbs_number > lately_number():
sys.stdout = open('date.txt','a')
bbs_lists = range(highest_number() +1, bbs_number +1)
for item in bbs_lists:
url_number = "url" + str(item)
try:
result = requests.get(url_number)
bs_number = BeautifulSoup(result.content, "lxml")
float_box = bs_number.find("div", {"class": "float_box"})
parameter_script = float_box
print("bs_obj()")
except AttributeError as e:
print("error")
with open('lately_number.txt', 'w') as f_last:
f_last.write(str(bbs_number))
Using the while statement above does not cause an error, but duplicate data will be output to date.txt.
I want to modify in the early stages of setting the range value, rather than removing duplicates in the later stages of typing in date.txt.
One possibility is that the existing lately_number() will output a duplicate range to date.txt, because sometimes it is not possible to enter the value correctly in the writing process of lately_number.txt.
I would be grateful if you can help me with a better function expression to add or replace.
The simplest way would be to read the date.txt into a set. Then, you can check the set to see if the date is already in there, and if it isn't, write the date to the date.txt file.
E.G.
uniqueDates = set()
#read file contents into a set.
with open("date.txt", "r") as f:
for line in f:
uniqueDates.add(line.strip()) #strip off the line ending \n
#ensure what we're writing to the date file isn't a duplicate.
with open("date.txt", "a") as f:
if("bs_obj()" not in uniqueDates):
f.write("bs_obj")
You'll probably need to adjust the logic a bit to fit your needs, but, I believe this is what you're trying to accomplish?
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
How to check and validate the format of input in Python.
For example - How to validate the format of PAN number using python. In PAN number first five values should be alpha next four values should be a numeric last value should be alpha. (Ex: abcde1234a)
Something like this,
def validate_pan_number(value):
"""
Validates if the given value is a valid PAN number or not, if not raise ValidationError
"""
if re.match(r'^[A-Z]{5}[0-9]{4}[A-Z]$', value):
return True
else:
raise ValidationError(
'%(value)s is not valid PAN number',
params={'value': value},
)
Obviously there is no ValidationError in python, the above is implemented for django, and here is the desciption of ValidationError
First method to validate the format of PAN number using python
or you can do like this also