Home Upgrade Search Memberlist Extras Hacker Tools Award Goals Help Wiki Contact

Python 

Help define a function plz.

So im trying to learn python, and i read xerotics thread and im trying to re write his log program using 3.4.1 i think i almost have it but i keep getting error saying log is not defined.

Heres the code.

Quote:def log():
Name = input("Name: ")
Age = input("Age: ")
Gender = input("Gender ")
Eye = input("Eye Color: ")

def main():
global x
choice = int(input("1.) Log a Person\n2.) Exit\n\nChoice (1-2): "))
if choice == 1:
Log() <----this is where the problem resides i think.
elif choice == 2:
x =0
else:
print ("Invalid Choice!")


any help please?


(Jan 12, 2015 05:28 PM)Impaired_ Wrote:  So im trying to learn python, and i read xerotics thread and im trying to re write his log program using 3.4.1 i think i almost have it but i keep getting error saying log is not defined.

Heres the code.

any help please?

LMAO i got it. i had..

def log():

log name was Log()

GG me.

A new question, when it logs the input it just logs the sequence in the .txt file.

f.write("\n\n"+"-"*25+"\nDay: "+day+"\nMonth: "+month+"\nYear: "+year+"\nNotes: "+notes+")
f.close()

Whats wrong here? please anyone?
[Image: sig40fdc.png]
make sure you:

file = open('file_name', w) #will create if nonexistent

file.write("\n\n"+"-"*25+"\nDay: "+day+"\nMonth: "+month+"\nYear: "+year+"\nNotes: "+notes+")

file.close()
(Jan 12, 2015 09:57 PM)Ju1c3b0x Wrote:  make sure you:

file = open('file_name', w) #will create if nonexistent

file.write("\n\n"+"-"*25+"\nDay: "+day+"\nMonth: "+month+"\nYear: "+year+"\nNotes: "+notes+")

file.close()

Thank you tremendously I will try it when I get home.

In the f.write code, will that save files to the dedicated folder each time a new log is taken??

Thanks again.
[Image: sig40fdc.png]
(Jan 13, 2015 06:15 AM)Impaired_ Wrote:  Thank you tremendously I will try it when I get home.

In the f.write code, will that save files to the dedicated folder each time a new log is taken??

Thanks again.

well if you put it in function like a update function

Code
def update():
    try:
      file = open('file_name'):
      file.write(your code here)
      file.close()
      print "Update Successful"

    except:
      print "Update Failed"

return

and then maybe have a Log function for when you take a new log and call the update function at the end of the Log function.

Just quick thoughts.
Thank you so much for your input, you're awesome!

I'm at work but ill give these a try when I get home!!
I just don't want the previously logged info to be overwritten.

I have big plans for this logger, I just don't know how to get it together. I've read tons about python but I'm more of a hands on learner.

One more question, I had an idea of being able to embed an img from the input of the user into the .txt file, any idea on how I could go about that??

You don't have to write the code lol, just point me in the right direction :)
[Image: sig40fdc.png]
(Jan 13, 2015 09:50 AM)Impaired_ Wrote:  Thank you so much for your input, you're awesome!

I'm at work but ill give these a try when I get home!!
I just don't want the previously logged info to be overwritten.

I have big plans for this logger, I just don't know how to get it together. I've read tons about python but I'm more of a hands on learner.

One more question, I had an idea of being able to embed an img from the input of the user into the .txt file, any idea on how I could go about that??

You don't have to write the code lol, just point me in the right direction :)

Not a problem, i'm happy to help. But as for embedding an image in a text file, i'm not quite sure. Might be better to just store the img file alone separately and call upon it with the data from the text file. It will appear as its all the same file.

Maybe look into a GUI if your wanting to go long term on this project.

Software development process if you get stuck:

What (Analysis)

How (Design)

Do It (Implementation)

Test (Testing and Debugging)

Use (Operation or Deployment)

Maintain (Refinement)
(Jan 13, 2015 10:47 AM)Ju1c3b0x Wrote:  Not a problem, i'm happy to help. But as for embedding an image in a text file, i'm not quite sure. Might be better to just store the img file alone separately and call upon it with the data from the text file. It will appear as its all the same file.

Maybe look into a GUI if your wanting to go long term on this project.

Software development process if you get stuck:

What (Analysis)

How (Design)

Do It (Implementation)

Test (Testing and Debugging)

Use (Operation or Deployment)

Maintain (Refinement)

Ok awesome thanks again :).

I plan on dabbling with the GUI after I get the program to actually work properly, last night I got stuck on line of code that's supposed to put user input into the .txt file, it just kept printing the code on the .txt file, not sure what's wrong with the code, but I'm using an old source so I'm guessing it's a translation issue.


I have a new problem.

So i got the program to create a folder, and i want it to save the .txt files in the folder instead of on my desktop.
Anyone have any suggestions?

Heres what i got so far. thanks.

Quote:global x
x = 1
import os
import os.path

def main():
global x
choice = int(input("1.) Log the Day\n2.) Exit\nChoice (1-2): "))
if choice == 1:
Log()
elif choice == 2:
x =0
else:
print ("Invalid Choice!")

def Log():
day = input("Day: ")
month = input("Month: ")
year = input ("Year: ")
notes = input("Notes ")

dir = ("Log")
os.makedirs("iGrow")

f = open("Log.txt", "a")
f.write("\n\n"+"-"*25+"\nDay: "+day+"\nMonth: "+month+"\nYear: "+year+"\nNotes: "+notes)
f.close()
print ("Log Successful\n\n")

def update():
try:
f = open("Grow Log.txt", "a")
f.write("\n\n"+"-"*25+"\nDay: "+day+"\nMonth: "+month+"\nYear: "+year+"\nNotes: "+notes)
f.close()
print ("Update Successful")

except:
print ("Update Failed")

while x == 1:
main()

[Image: sig40fdc.png]


Possibly Related Threads...
Thread / Author Replies Views Last Post
[C] by FhackMar 2, 2022 03:52 AM 4 307 Mar 2, 2022 03:52 AM
Last Post: Fhack
[C] by SGUdyrNov 16, 2016 12:39 PM 19 337 Nov 16, 2016 12:39 PM
Last Post: Sajuuk
[C] by TicomaFeb 12, 2016 01:34 PM 3 128 Feb 12, 2016 01:34 PM
Last Post: Annabelle Lee