Posts: 401
Threads: 141
Joined: Oct 2009
Reputation:
5
10-15-2009, 08:47 PM
(This post was last modified: 10-15-2009, 08:47 PM by nevets04.)
Code: x = open("file.txt", "w")
y = raw_input()
x.write(y)
x.close
x = open("file.txt", "r")
x.read
Posts: 97
Threads: 19
Joined: Oct 2009
Reputation:
0
interesting........thank you good share!
CHINAMAN
Quote:i like to make myself belie
Posts: 106
Threads: 10
Joined: Oct 2009
Reputation:
3
Thanks for this, could you use this to read settings?
Posts: 103
Threads: 7
Joined: Oct 2009
Reputation:
5
10-31-2009, 08:27 AM
(This post was last modified: 10-31-2009, 08:27 AM by Fallen.)
(10-29-2009, 02:19 AM)fail ninja Wrote: Thanks for this, could you use this to read settings?
Code: import time, re, sys
class ResBot_Main( object ):
def __init__( self, ConfigurationFile ):
self.Configuration_File_Values = {}
if os.path.exists( ConfigurationFile ):
self.ResBot_Config_Reader( ConfigurationFile )
else:
self.ResBot_Error( True, "Configuration File...\"%s\" Does not exist" % ( ConfigurationFile ) )
def ResBot_Error( self, Fatal, Error_Message ):
if Fatal == True:
print ( "[ResBot]Fatal Error: %s\n\tRecieved On: %s\nShutting Down..." % ( Error_Message, time.strftime( "%H:%M:%S" ) ) )
sys.exit( 1 )
else:
print ( "[ResBot]Error: %s\n\tRecieved On: %s" % ( Error_Message, time.strftime( "%H:%M:%S" ) ) )
def ResBot_Config_Reader(self, ConfigurationFile ):
try:
Config_File_Handle = open( ConfigurationFile, "r" )
except Exception:
self.ResBot_Error( True, "Unable to read Configuration File...\"%s\"" % ( ConfigurationFile ) )
Config_File_Buffer = Config_File_Handle.read( )
Config_File_Line_Counter = 0
for Config_Line in Config_File_Buffer.split( "\n" ):
Config_File_Line_Counter += 1
Config_Line = re.sub( "[\s'\"]", "", Config_Line )
if Config_Line[ 0 ] == "#":
continue
Config_Line_Key_Value = Config_Line.split( "=" )
try:
self.Configuration_File_Values[ Config_Line_Key_Value[ 0 ] ] = Config_Line_Key_Value[ 1 ]
except Exception:
self.ResBot_Error( False, "Syntax Error in \"%s\" on Line %i..." % ( ConfigurationFile, Config_File_Line_Counter ) )
Terrorcore, unleash, extermination
Hyper real, cold blood, determination
fudge them, I like this sensation
Incredible, I from the annihilation
Posts: 130
Threads: 13
Joined: Oct 2009
Reputation:
10
(10-31-2009, 08:27 AM)Fallen Wrote: Code: import time, re, sys
class ResBot_Main( object ):
def __init__( self, ConfigurationFile ):
self.Configuration_File_Values = {}
if os.path.exists( ConfigurationFile ):
self.ResBot_Config_Reader( ConfigurationFile )
else:
self.ResBot_Error( True, "Configuration File...\"%s\" Does not exist" % ( ConfigurationFile ) )
def ResBot_Error( self, Fatal, Error_Message ):
if Fatal == True:
print ( "[ResBot]Fatal Error: %s\n\tRecieved On: %s\nShutting Down..." % ( Error_Message, time.strftime( "%H:%M:%S" ) ) )
sys.exit( 1 )
else:
print ( "[ResBot]Error: %s\n\tRecieved On: %s" % ( Error_Message, time.strftime( "%H:%M:%S" ) ) )
def ResBot_Config_Reader(self, ConfigurationFile ):
try:
Config_File_Handle = open( ConfigurationFile, "r" )
except Exception:
self.ResBot_Error( True, "Unable to read Configuration File...\"%s\"" % ( ConfigurationFile ) )
Config_File_Buffer = Config_File_Handle.read( )
Config_File_Line_Counter = 0
for Config_Line in Config_File_Buffer.split( "\n" ):
Config_File_Line_Counter += 1
Config_Line = re.sub( "[\s'\"]", "", Config_Line )
if Config_Line[ 0 ] == "#":
continue
Config_Line_Key_Value = Config_Line.split( "=" )
try:
self.Configuration_File_Values[ Config_Line_Key_Value[ 0 ] ] = Config_Line_Key_Value[ 1 ]
except Exception:
self.ResBot_Error( False, "Syntax Error in \"%s\" on Line %i..." % ( ConfigurationFile, Config_File_Line_Counter ) )
lol Fallen he wont even know what you're trying to show him in that script ^^
Posts: 1,675
Threads: 194
Joined: Oct 2009
Reputation:
56
(11-04-2009, 11:50 PM)Nyx- Wrote: lol Fallen he wont even know what you're trying to show him in that script ^^
How could you possibly know that?
Posts: 401
Threads: 141
Joined: Oct 2009
Reputation:
5
(10-31-2009, 08:27 AM)Fallen Wrote: Code: import time, re, sys
class ResBot_Main( object ):
def __init__( self, ConfigurationFile ):
self.Configuration_File_Values = {}
if os.path.exists( ConfigurationFile ):
self.ResBot_Config_Reader( ConfigurationFile )
else:
self.ResBot_Error( True, "Configuration File...\"%s\" Does not exist" % ( ConfigurationFile ) )
def ResBot_Error( self, Fatal, Error_Message ):
if Fatal == True:
print ( "[ResBot]Fatal Error: %s\n\tRecieved On: %s\nShutting Down..." % ( Error_Message, time.strftime( "%H:%M:%S" ) ) )
sys.exit( 1 )
else:
print ( "[ResBot]Error: %s\n\tRecieved On: %s" % ( Error_Message, time.strftime( "%H:%M:%S" ) ) )
def ResBot_Config_Reader(self, ConfigurationFile ):
try:
Config_File_Handle = open( ConfigurationFile, "r" )
except Exception:
self.ResBot_Error( True, "Unable to read Configuration File...\"%s\"" % ( ConfigurationFile ) )
Config_File_Buffer = Config_File_Handle.read( )
Config_File_Line_Counter = 0
for Config_Line in Config_File_Buffer.split( "\n" ):
Config_File_Line_Counter += 1
Config_Line = re.sub( "[\s'\"]", "", Config_Line )
if Config_Line[ 0 ] == "#":
continue
Config_Line_Key_Value = Config_Line.split( "=" )
try:
self.Configuration_File_Values[ Config_Line_Key_Value[ 0 ] ] = Config_Line_Key_Value[ 1 ]
except Exception:
self.ResBot_Error( False, "Syntax Error in \"%s\" on Line %i..." % ( ConfigurationFile, Config_File_Line_Counter ) )
ehh... I don't know what that is.. but this reads a text file
Code: f = open("file.txt", 'r')
for line in f:
print line,
Posts: 103
Threads: 7
Joined: Oct 2009
Reputation:
5
(11-14-2009, 11:31 PM)nevets04 Wrote: ehh... I don't know what that is.. but this reads a text file
Code: f = open("file.txt", 'r')
for line in f:
print line,
Its a class in which reads variables from text files, example
[Config File]
Host = "127.0.0.1"
Port = 6667
lol=abc
so then
self.Configuration_File_Values["Host"] = "127.0.0.1"
self.Configuration_File_Values["Port"] = "6667"
self.Configuration_File_Values["lol"] = "abc"
etc
Terrorcore, unleash, extermination
Hyper real, cold blood, determination
fudge them, I like this sensation
Incredible, I from the annihilation
|