Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #91736 > unrolled thread
| Started by | "Skybuck Flying" <skybuck2000@hotmail.com> |
|---|---|
| First post | 2015-06-02 02:29 +0200 |
| Last post | 2015-06-09 04:31 +0200 |
| Articles | 20 on this page of 57 — 10 participants |
Back to article view | Back to comp.lang.python
Parser needed. "Skybuck Flying" <skybuck2000@hotmail.com> - 2015-06-02 02:29 +0200
Re: Parser needed. "Skybuck Flying" <skybuck2000@hotmail.com> - 2015-06-02 02:55 +0200
Re: Parser needed. "Skybuck Flying" <skybuck2000@hotmail.com> - 2015-06-02 03:02 +0200
Re: Parser needed. "Skybuck Flying" <skybuck2000@hotmail.com> - 2015-06-02 03:10 +0200
Re: Parser needed. "Skybuck Flying" <skybuck2000@hotmail.com> - 2015-06-02 03:16 +0200
Re: Parser needed. "Skybuck Flying" <skybuck2000@hotmail.com> - 2015-06-02 03:27 +0200
Re: Parser needed. "Skybuck Flying" <skybuck2000@hotmail.com> - 2015-06-02 03:29 +0200
Re: Parser needed. "Skybuck Flying" <skybuck2000@hotmail.com> - 2015-06-02 03:31 +0200
Re: Parser needed. "Skybuck Flying" <skybuck2000@hotmail.com> - 2015-06-02 03:34 +0200
Re: Parser needed. "Skybuck Flying" <skybuck2000@hotmail.com> - 2015-06-02 04:02 +0200
Re: Parser needed. "Skybuck Flying" <skybuck2000@hotmail.com> - 2015-06-02 04:22 +0200
Re: Parser needed. "Skybuck Flying" <skybuck2000@hotmail.com> - 2015-06-02 04:27 +0200
Re: Parser needed. "Skybuck Flying" <skybuck2000@hotmail.com> - 2015-06-02 04:39 +0200
Re: Parser needed. Joel Goldstick <joel.goldstick@gmail.com> - 2015-06-01 21:41 -0400
Re: Parser needed. "Skybuck Flying" <skybuck2000@hotmail.com> - 2015-06-02 04:04 +0200
Re: Parser needed. "Skybuck Flying" <skybuck2000@hotmail.com> - 2015-06-02 02:56 +0200
Re: Parser needed. "Skybuck Flying" <skybuck2000@hotmail.com> - 2015-06-02 03:01 +0200
Re: Parser needed. "Skybuck Flying" <skybuck2000@hotmail.com> - 2015-06-02 03:03 +0200
Re: Parser needed. "Skybuck Flying" <skybuck2000@hotmail.com> - 2015-06-02 03:04 +0200
Re: Parser needed. "Skybuck Flying" <skybuck2000@hotmail.com> - 2015-06-02 03:07 +0200
Re: Parser needed. "Skybuck Flying" <skybuck2000@hotmail.com> - 2015-06-02 03:07 +0200
Re: Parser needed. Michael Torrie <torriem@gmail.com> - 2015-06-01 19:12 -0600
Re: Parser needed. "Skybuck Flying" <skybuck2000@hotmail.com> - 2015-06-02 03:19 +0200
Re: Parser needed. Michael Torrie <torriem@gmail.com> - 2015-06-01 19:31 -0600
Re: Parser needed. "Skybuck Flying" <skybuck2000@hotmail.com> - 2015-06-02 03:35 +0200
Re: Parser needed. "Skybuck Flying" <skybuck2000@hotmail.com> - 2015-06-02 04:11 +0200
Re: Parser needed. "Skybuck Flying" <skybuck2000@hotmail.com> - 2015-06-02 04:20 +0200
Re: Parser needed. Grant Edwards <invalid@invalid.invalid> - 2015-06-02 13:48 +0000
Re: Parser needed. Mark Lawrence <breamoreboy@yahoo.co.uk> - 2015-06-02 04:42 +0100
Re: Parser needed. "Skybuck Flying" <skybuck2000@hotmail.com> - 2015-06-02 06:23 +0200
Re: Parser needed. "Skybuck Flying" <skybuck2000@hotmail.com> - 2015-06-02 06:29 +0200
Re: Parser needed. "Skybuck Flying" <skybuck2000@hotmail.com> - 2015-06-02 06:39 +0200
Re: Parser needed. "Skybuck Flying" <skybuck2000@hotmail.com> - 2015-06-02 06:45 +0200
Re: Parser needed. "Skybuck Flying" <skybuck2000@hotmail.com> - 2015-06-02 06:51 +0200
Re: Parser needed. "Skybuck Flying" <skybuck2000@hotmail.com> - 2015-06-02 06:53 +0200
Re: Parser needed. MRAB <python@mrabarnett.plus.com> - 2015-06-02 17:43 +0100
Re: Parser needed. "Skybuck Flying" <skybuck2000@hotmail.com> - 2015-06-02 19:09 +0200
Re: Parser needed. "Skybuck Flying" <skybuck2000@hotmail.com> - 2015-06-04 18:01 +0200
Re: Parser needed. "Skybuck Flying" <skybuck2000@hotmail.com> - 2015-06-04 19:02 +0200
Re: Parser needed. Steven D'Aprano <steve@pearwood.info> - 2015-06-05 03:14 +1000
Re: Parser needed. Michael Torrie <torriem@gmail.com> - 2015-06-04 11:25 -0600
Re: Parser needed. "Skybuck Flying" <skybuck2000@hotmail.com> - 2015-06-04 19:23 +0200
Re: Parser needed. "Skybuck Flying" <skybuck2000@hotmail.com> - 2015-06-04 19:34 +0200
Re: Parser needed. "Skybuck Flying" <skybuck2000@hotmail.com> - 2015-06-04 19:38 +0200
Re: Parser needed. "Skybuck Flying" <skybuck2000@hotmail.com> - 2015-06-04 19:44 +0200
Re: Parser needed. "Skybuck Flying" <skybuck2000@hotmail.com> - 2015-06-04 19:50 +0200
Re: Parser needed. "Skybuck Flying" <skybuck2000@hotmail.com> - 2015-06-04 20:00 +0200
Re: Parser needed. "Skybuck Flying" <skybuck2000@hotmail.com> - 2015-06-09 04:30 +0200
Re: Parser needed. "Skybuck Flying" <skybuck2000@hotmail.com> - 2015-06-09 14:20 +0200
Re: Parser needed. Michael Torrie <torriem@gmail.com> - 2015-06-09 17:33 -0600
Re: Parser needed. Rustom Mody <rustompmody@gmail.com> - 2015-06-09 19:08 -0700
Re: Parser needed. "Skybuck Flying" <skybuck2000@hotmail.com> - 2015-06-11 13:15 +0200
Re: Parser needed. Joel Goldstick <joel.goldstick@gmail.com> - 2015-06-11 08:35 -0400
Re: Parser needed. Larry Martell <larry.martell@gmail.com> - 2015-06-11 08:38 -0400
Re: Parser needed. Rustom Mody <rustompmody@gmail.com> - 2015-06-11 08:35 -0700
Re: Parser needed. Tony the Tiger <tony@tiger.invalid> - 2015-06-14 16:01 +0000
Re: Parser needed. "Skybuck Flying" <skybuck2000@hotmail.com> - 2015-06-09 04:31 +0200
Page 2 of 3 — ← Prev page 1 [2] 3 Next page →
| From | "Skybuck Flying" <skybuck2000@hotmail.com> |
|---|---|
| Date | 2015-06-02 03:07 +0200 |
| Message-ID | <ad05d$556d01dc$5419aafe$41358@news.ziggo.nl> |
| In reply to | #91747 |
Link looks a bit odd, home index link: Nice python documentation/tutorial/help: http://www.tutorialspoint.com/python/index.htm Bye, Skybuck.
[toc] | [prev] | [next] | [standalone]
| From | Michael Torrie <torriem@gmail.com> |
|---|---|
| Date | 2015-06-01 19:12 -0600 |
| Message-ID | <mailman.31.1433207544.13271.python-list@python.org> |
| In reply to | #91736 |
On 06/01/2015 06:29 PM, Skybuck Flying wrote: > The parser should be able to parse a textfile of somewhere between 20.000 > lines to 50.000 lines in about 1 to 2 seconds. > > My environment is SikuliX 1.1 I don't have any inclination to examine your input files, but you could certainly mock up a parser fairly quickly with the fantastic pyparsing module (you'll have to install it from your distro's package manager, or through pip. Once you have figure out how to parse the data you can fill in your data structures as you go along. Pyparsing has pretty good docs; just google for it. Usually first I get pyparsing working on my input file, then I add code to each of the steps along the way to actually do something with the data that has been parsed. You could parse it manually using regular expressions if the data is fairly structured and regular.
[toc] | [prev] | [next] | [standalone]
| From | "Skybuck Flying" <skybuck2000@hotmail.com> |
|---|---|
| Date | 2015-06-02 03:19 +0200 |
| Message-ID | <52c36$556d048a$5419aafe$44775@news.ziggo.nl> |
| In reply to | #91752 |
"Michael Torrie" wrote in message
news:mailman.31.1433207544.13271.python-list@python.org...
On 06/01/2015 06:29 PM, Skybuck Flying wrote:
> The parser should be able to parse a textfile of somewhere between 20.000
> lines to 50.000 lines in about 1 to 2 seconds.
>
> My environment is SikuliX 1.1
"
I don't have any inclination to examine your input files, but you could
certainly mock up a parser fairly quickly with the fantastic pyparsing
module (you'll have to install it from your distro's package manager, or
through pip.
Once you have figure out how to parse the data you can fill in your data
structures as you go along. Pyparsing has pretty good docs; just google
for it. Usually first I get pyparsing working on my input file, then I
add code to each of the steps along the way to actually do something
with the data that has been parsed.
You could parse it manually using regular expressions if the data is
fairly structured and regular.
"
It seems the data file is structure as:
{
<structure name>
{
<SomeField> <SomeData>
<another structure name>
{
<SomeField> <SomeData>
}
}
}
Example:
{
createdEnts
{
EntityRef 29294664
ContainerID 65086
EntitySendDistance 1500.000000
entityTypeEnum ENTITYCRITTER
CostumeV5
{
hReferencedCostume Loot_Space_Common_01
}
}
}
How hard would it be to encode that into pyparser ?
Bye,
Skybuck.
[toc] | [prev] | [next] | [standalone]
| From | Michael Torrie <torriem@gmail.com> |
|---|---|
| Date | 2015-06-01 19:31 -0600 |
| Message-ID | <mailman.33.1433208676.13271.python-list@python.org> |
| In reply to | #91755 |
On 06/01/2015 07:19 PM, Skybuck Flying wrote: > How hard would it be to encode that into pyparser ? Check out the docs and you probably will get an idea. The only real way to find out is to try it. Is this file from a certain program? If so, it's possible someone has already written a python library for reading it.
[toc] | [prev] | [next] | [standalone]
| From | "Skybuck Flying" <skybuck2000@hotmail.com> |
|---|---|
| Date | 2015-06-02 03:35 +0200 |
| Message-ID | <25a48$556d086a$5419aafe$52911@news.ziggo.nl> |
| In reply to | #91761 |
On 06/01/2015 07:19 PM, Skybuck Flying wrote: > How hard would it be to encode that into pyparser ? " Check out the docs and you probably will get an idea. The only real way to find out is to try it. Is this file from a certain program? If so, it's possible someone has already written a python library for reading it. " It's from a game called Star Trek Online, I think there is a C# parser for it. The ammount of data I need from this file is very limited. I don't want to spent too much time on a solution. I have perhaps today to try and get a solution working ;) So no time to learn complex pyparsers ? If you can provide a simple example I might give it a shot ;) Otherwise I try to wing my own. Your help might be usefull later on if my own parser sux, fails or is too slow ;) Bye, Skybuck.
[toc] | [prev] | [next] | [standalone]
| From | "Skybuck Flying" <skybuck2000@hotmail.com> |
|---|---|
| Date | 2015-06-02 04:11 +0200 |
| Message-ID | <9dd74$556d10b2$5419aafe$6564@news.ziggo.nl> |
| In reply to | #91763 |
I tried running this in SikuliX 1.1 from pyparsing import Word, alphas greet = Word( alphas ) + "," + Word( alphas ) + "!" greeting = greet.parseString( "Hello, World!" ) print greeting Doesn't seem to run pyparser module missing. Another reason why not to use it, unfortunately. Not sure if it's possible to somehow include it with SikuliX. This might mean the end for this little experiment. I think SikuliX/Jython might be too slow for parsing purposes which is kinda odd... since it can do 500.000 if statements last time I tested it... but when it comes to dealing with characters it seems to turn into a pile of shit ? Hmmm.. maybe unicode processing has something to do with it :) Perhaps I should write a small little test program to test this "python/jython" is a "piece of char shit" theory. Yes interesting test. Bye, Skybuck.
[toc] | [prev] | [next] | [standalone]
| From | "Skybuck Flying" <skybuck2000@hotmail.com> |
|---|---|
| Date | 2015-06-02 04:20 +0200 |
| Message-ID | <40cd2$556d12f7$5419aafe$8907@news.ziggo.nl> |
| In reply to | #91768 |
Test program shows, python/sikulix can handle about 3m chars per second so I must continue with a parser attempt. # test char processing speed. # test if sikulix 1.1, python, jython/whatever is a piece of shit when it comes to parsing dealing with characters, unicode processing bottleneck theory. import time import random MaxChars = 3000000 MinChar = 33 MaxChar = 200 Chars = [] def GenerateChars(): vRandomChar = "" for vIndex in range(0, MaxChars): vRandomChar = chr(random.randrange(MinChar,MaxChar)) Chars.append(vRandomChar) return def ProcessChars(): Result = 0 for vIndex in range(0, MaxChars): if Chars[vIndex] == chr(45): Result = Result + 1 return Result Tick1 = time.time() GenerateChars() Tick2 = time.time() Seconds = Tick2 - Tick1 print "GenerateChars seconds: " + str(Seconds) Tick1 = time.time() ProcessChars() Tick2 = time.time() Seconds = Tick2 - Tick1 print "ProcessChars seconds: " + str(Seconds) #print Chars
[toc] | [prev] | [next] | [standalone]
| From | Grant Edwards <invalid@invalid.invalid> |
|---|---|
| Date | 2015-06-02 13:48 +0000 |
| Message-ID | <mkkc7r$je4$1@reader1.panix.com> |
| In reply to | #91755 |
On 2015-06-02, Skybuck Flying <skybuck2000@hotmail.com> wrote:
><structure name>
> {
> <SomeField> <SomeData>
> <another structure name>
> {
> <SomeField> <SomeData>
> }
> }
IOW, it's almost, but not quite, JSON.
--
Grant Edwards grant.b.edwards Yow! My vaseline is
at RUNNING...
gmail.com
[toc] | [prev] | [next] | [standalone]
| From | Mark Lawrence <breamoreboy@yahoo.co.uk> |
|---|---|
| Date | 2015-06-02 04:42 +0100 |
| Message-ID | <mailman.37.1433216711.13271.python-list@python.org> |
| In reply to | #91736 |
On 02/06/2015 01:29, Skybuck Flying wrote: > Hello, > > I need some kind of parser and some kind of way to access the data > contained in a file like the one below: > > (text file): > > http://www.skybuck.org/Games/StartrekOnline/Parser/SpaceFleetAlertEnemyExample.demo > > > I am interested in learning the entity numbers: > > "EntityRef <number>" > > and their positions: > > " > Pos <x>, <z>, <y> > " > > I am also interested in the creation of these entities, especially their > type: > > "entityTypeEnum <type>" > > So basically the parser should produce a few lists: > > EntityNumber = [] > EntityType = [] > EntityPositionX = [] > EntityPositionY = [] > EntityPositionZ = [] > > Any extra information about entities is welcome. > > The parser should be able to parse a textfile of somewhere between > 20.000 lines to 50.000 lines in about 1 to 2 seconds. > > My environment is SikuliX 1.1 > > Bye, > Skybuck. See here http://nedbatchelder.com/text/python-parsers.html Can you also please stop sending so many emails as I believe some people still pay by the byte. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence
[toc] | [prev] | [next] | [standalone]
| From | "Skybuck Flying" <skybuck2000@hotmail.com> |
|---|---|
| Date | 2015-06-02 06:23 +0200 |
| Message-ID | <9c6eb$556d2fa6$5419aafe$8770@news.ziggo.nl> |
| In reply to | #91736 |
Here is a parser for sto demo files written in C# maybe it can be of some use, check trunk folders: http://sourceforge.net/p/stodemolauncher/code/HEAD/tree/ Bye, Skybuck.
[toc] | [prev] | [next] | [standalone]
| From | "Skybuck Flying" <skybuck2000@hotmail.com> |
|---|---|
| Date | 2015-06-02 06:29 +0200 |
| Message-ID | <81e68$556d3120$5419aafe$9437@news.ziggo.nl> |
| In reply to | #91784 |
Together with this it's might be of some use: http://codeconverter.sharpdevelop.net/SnippetConverter.aspx It converts C# to Python pretty fast. I'll give it a try to see if it can work. Bye, Skybuck.
[toc] | [prev] | [next] | [standalone]
| From | "Skybuck Flying" <skybuck2000@hotmail.com> |
|---|---|
| Date | 2015-06-02 06:39 +0200 |
| Message-ID | <b352f$556d338a$5419aafe$10196@news.ziggo.nl> |
| In reply to | #91786 |
Hmm this parser uses an interesting technique:
if line.Contains("activePlayerRef"):
self._activePlayerRef =
Convert.ToInt64(line.Substring(line.LastIndexOf("activePlayerRef") + 16))
I'll see if python can do this as well... ;)
Bye,
Skybuck.
[toc] | [prev] | [next] | [standalone]
| From | "Skybuck Flying" <skybuck2000@hotmail.com> |
|---|---|
| Date | 2015-06-02 06:45 +0200 |
| Message-ID | <a1ba9$556d34d1$5419aafe$10658@news.ziggo.nl> |
| In reply to | #91787 |
Example for python:
MyString = "Hello World"
print MyString.rfind("World")
if MyString.rfind("World"):
print "yes"
else:
print "no"
Pretty cool.
Bye,
Skybuck.
[toc] | [prev] | [next] | [standalone]
| From | "Skybuck Flying" <skybuck2000@hotmail.com> |
|---|---|
| Date | 2015-06-02 06:51 +0200 |
| Message-ID | <bd780$556d3658$5419aafe$11125@news.ziggo.nl> |
| In reply to | #91788 |
If some of this code could be made to work it could be of some use:
ParserEngine is the least important...
MessageParser is interesting.
class AbstractSectionsParser(AbstractParser):
# Provides a method to return a list of sections
def GetResult(self):
# Returns the list with the found resources.
pass
class AbstractParser(object):
# Must be implemented by objects that want to use the DemoFileParser.
# Provides an empty implementation for conveniance
def StartParsing(self, filename):
# Is called before the first line is parsed.
# "filename" Absolute path to the file being parsed
pass
def NewLine(self, line, lineNumber):
# Is called by the parser when it has fetched a new line
# "line" Content of the line
# "lineNumber" Current line number (0 index)
pass
def HasAllInformation(self):
# Is called before each line is read. When you return true, parsing
# will stop prematurely.
# returns true if this plugin does not want to process any more lines
return False
def StopParsing(self, lineCount):
# Is called, when all lines have been read by the parser.
# "lineCount" Total number of lines in the demo file.
pass
class MessagesParser(AbstractSectionsParser):
# Parses a demo file for "Notifications"
# The list in which the parser stores the pprocessed messages
# The string we are looking for in parsed messages
# Number of open braces ("{" increments, "}" decrements)
# The number of open braces at the last encounter of "Messages"
# The line at which the last "Messages" section started
# Flag that indicates if the parser has currently entered a
# "Messages" section
# Flag that indicates if we are currently processing a Messages
# section that contains the messageSearchString
# The last visited message test
# The command identifier
# The time index of the message in seconds
# The entity ref for this message
def __init__(self, messageSearchString):
# Creates a new MessageParser object
# <param name="messageSearchString">The string to look for in parsed
self._result = List[DemoSection]()
self._braceLevel = 0
self._lastMessagesBraceLevel = 0
self._lastMessagesSectionStart = 0
self._inMessagesSection = False
self._inSearchSection = False
self._messageText = ""
self._command = -1
self._time = -1
self._entityRef = -1
self._messageSearchString = messageSearchString
def NewLine(self, line, lineNumber):
# Is called by the parser when it has fetched a new line
# <param name="line">Content of the line</param>
# <param name="lineNumber">Current line number (0 index)</param>
if line.Trim().StartsWith("Messages"):
self._lastMessagesSectionStart = lineNumber
self._lastMessagesBraceLevel = self._braceLevel
self._inMessagesSection = True
if self._inMessagesSection and line.Trim().StartsWith("Time"):
timeString = line.Substring(line.IndexOf("Time ") + 5)
self._time = Double.Parse(timeString,
System.Globalization.CultureInfo.GetCultureInfo("en-US").NumberFormat)
if self._inMessagesSection and line.Trim().StartsWith("Message ") and
line.Contains(self._messageSearchString):
self._inSearchSection = True
self._messageText = line.Substring(line.IndexOf("Message ") + 8)
if self._inMessagesSection and line.Trim().StartsWith("Command"):
self._command = Convert.ToInt32(line.Substring(line.IndexOf("Command ") +
8))
if self._inMessagesSection and line.Trim().StartsWith("EntityRef"):
self._entityRef = Convert.ToInt32(line.Substring(line.IndexOf("EntityRef
") + 10))
if self._inSearchSection and line.Trim().StartsWith("}") and
self._braceLevel - 1 == self._lastMessagesBraceLevel:
self._inMessagesSection = False
self._inSearchSection = False
message = DemoMessage()
message.StartLine = self._lastMessagesSectionStart
message.EndLine = lineNumber + 1
message.Message = self._messageText
message.Time = self._time
message.Command = self._command
message.EntityRef = self._entityRef
self._result.Add(message)
if line.Trim().StartsWith("{"):
self._braceLevel += 1
if line.Trim().StartsWith("}"):
self._braceLevel -= 1
def GetResult(self):
# Returns the list of parsed messages
# <returns>Returns a list of parsed messages</returns>
return self._result
class ParserEngine(object):
def Parse(filename, plugin):
""" <summary>
Parses a demo file
</summary>
<param name="filename">The file to be parsed</param>
<param name="plugin">The ParserPlugin to use</param>
<returns>true if parsing was successful</returns>
"""
# here we read the contents of the demo file line-by-line
line = ""
lineNumber = 0
# only run if the file actually exists
if File.Exists(filename):
plugin.StartParsing(filename)
# start reading file line by line
file = None
try:
file = StreamReader(filename)
# parse as long as we don't have all information and there are still
lines to read
while not plugin.HasAllInformation() and (line = file.ReadLine()) !=
None:
plugin.NewLine(line, lineNumber)
lineNumber += 1
plugin.StopParsing(lineNumber)
except Exception, e:
# report exception
MessageBox.Show("The demo file " + filename + " could not be parsed for
meta information.\n" + "Please report the following error under \"Updates &
Help\"\n" + e.Message, "Error Parsing Demo Directory", MessageBoxButtons.OK,
MessageBoxIcon.Error)
finally:
# close file, no matter what
if file != None:
file.Close()
# abort parsing, if exception occured
if file == None:
return False
else:
# report error, if file does not exist
MessageBox.Show("The demo file " + filename + " does not exist.\n" +
"Please report the this error under \"Updates & Help\"\n", "File Not Found",
MessageBoxButtons.OK, MessageBoxIcon.Error)
return False
return True
Parse = staticmethod(Parse)
def Parse(fileContents, plugin):
""" <summary>
Parses a demo file in memory
</summary>
<param name="fileContents">The contents of a demo file to be
parsed</param>
<param name="plugin">The ParserPlugin to use</param>
<returns>true if parsing was successful</returns>
""" #, ToolStripProgressBar progressBar)
if fileContents != None:
# here we read the contents of the demo file line-by-line
lineNumber = 0
#progressBar.Maximum = fileContents.Count();
#progressBar.Step = 1;
enumerator = fileContents.GetEnumerator()
plugin.StartParsing("no file")
# parse as long as we don't have all information and there are still
lines to read
while not plugin.HasAllInformation() and enumerator.MoveNext():
plugin.NewLine(enumerator.Current, lineNumber)
lineNumber += 1
#progressBar.PerformStep();
plugin.StopParsing(lineNumber)
else:
# report error, if file does not exist
MessageBox.Show("The demo file buffer was null.\n" + "Please report the
this error under \"Updates & Help\"\n", "Demo File Buffer Null",
MessageBoxButtons.OK, MessageBoxIcon.Error)
return False
return True
Parse = staticmethod(Parse)
Bye,
Skybuck.
[toc] | [prev] | [next] | [standalone]
| From | "Skybuck Flying" <skybuck2000@hotmail.com> |
|---|---|
| Date | 2015-06-02 06:53 +0200 |
| Message-ID | <16767$556d36d6$5419aafe$11344@news.ziggo.nl> |
| In reply to | #91791 |
Actually that's not true... messages not that interesting. This C# parser does not parse what I want which is: "updates" and "positions". Thus I rejected this parser some days ago. But it's technique could be handy. Bye, Skybuck.
[toc] | [prev] | [next] | [standalone]
| From | MRAB <python@mrabarnett.plus.com> |
|---|---|
| Date | 2015-06-02 17:43 +0100 |
| Message-ID | <mailman.71.1433263397.13271.python-list@python.org> |
| In reply to | #91788 |
On 2015-06-02 05:45, Skybuck Flying wrote:
> Example for python:
>
> MyString = "Hello World"
>
> print MyString.rfind("World")
> if MyString.rfind("World"):
> print "yes"
> else:
> print "no"
>
> Pretty cool.
>
.rfind returns the index if found, -1 if not found.
"World".rfind("World") returns 0, which will be treated as false.
"foo".rfind("World") returns -1, which will be treated as true.
[toc] | [prev] | [next] | [standalone]
| From | "Skybuck Flying" <skybuck2000@hotmail.com> |
|---|---|
| Date | 2015-06-02 19:09 +0200 |
| Message-ID | <bbe54$556de345$5419aafe$40024@news.ziggo.nl> |
| In reply to | #91859 |
"MRAB" wrote in message
news:mailman.71.1433263397.13271.python-list@python.org...
On 2015-06-02 05:45, Skybuck Flying wrote:
> Example for python:
>
> MyString = "Hello World"
>
> print MyString.rfind("World")
> if MyString.rfind("World"):
> print "yes"
> else:
> print "no"
>
> Pretty cool.
>
"
.rfind returns the index if found, -1 if not found.
"World".rfind("World") returns 0, which will be treated as false.
"foo".rfind("World") returns -1, which will be treated as true.
"
Yes I agree, that code is not very clean.
Hence I added:
print MyString.rfind("World")
Just to figure out if it indeed prints an index.
Index 0 might be of use too, so checking for true/false like I did above
should not be done.
Consider it incorrect code.
However I didn't care at the time cause I was in a hurry... I knew it was
dirty but this post correct that and warns people not to write code like I
did... just in case ! ;)
And also to let you know I am full aware of the shady nature of this code !
;) =D
Bye,
Skybuck :)
[toc] | [prev] | [next] | [standalone]
| From | "Skybuck Flying" <skybuck2000@hotmail.com> |
|---|---|
| Date | 2015-06-04 18:01 +0200 |
| Message-ID | <ad067$55707666$5419aafe$54543@news.ziggo.nl> |
| In reply to | #91788 |
Yes these string processing techniques will work very nicely and very fast:
cut and pasted an example but should work... now I developed it a bit
further, bye ,bye.
BotDemoFolder = "C:\\Games\\Startrek Online\\Startrek Online\\Cryptic
Studios\\Star Trek Online\\Live\\demos"
BotDemoFile = "SpaceFleetAlertEnemyExample.demo"
import time
def ProcessEntityRef():
global DemoChars
global CreatedEntsIndex
StartIndex = DemoChars.find("EntityRef", CreatedEntsIndex)
StopIndex = DemoChars.find("\n",StartIndex)
if StartIndex <> -1:
Ref = DemoChars[StartIndex:StopIndex]
else:
Ref = 0
return Ref
def ProcessCreatedEntities():
global DemoChars
global CreatedEntsIndex
CreatedEntsIndex = 0
while (CreatedEntsIndex <> -1): # and (CreatedEntsIndex < 100000):
CreatedEntsIndex = DemoChars.find("createdEnts", CreatedEntsIndex)
RefNumber = ProcessEntityRef()
if CreatedEntsIndex <> -1:
CreatedEntsIndex = CreatedEntsIndex + 1
print "RefNumber: " + str(RefNumber)
return
def Main():
global DemoChars
DemoFilePath = BotDemoFolder + "\\" + BotDemoFile
FileObject = open( DemoFilePath, "r")
# DemoLines = FileObject.readlines()
# ParseDemoLines( DemoLines )
DemoChars = FileObject.read()
ProcessCreatedEntities()
# Index = DemoChars.find("createdEnts")
# print DemoChars[Index:Index+5]
# rfind
# ParseDemoChars( DemoChars )
FileObject.close()
return
print "program started"
Tick1 = time.time()
Main()
Tick2 = time.time()
Seconds = Tick2 - Tick1
print "program finished"
# Skybuck
[toc] | [prev] | [next] | [standalone]
| From | "Skybuck Flying" <skybuck2000@hotmail.com> |
|---|---|
| Date | 2015-06-04 19:02 +0200 |
| Message-ID | <7cd38$557084b9$5419aafe$9688@news.ziggo.nl> |
| In reply to | #91736 |
Yeah... my first nice parser for this kind of stuff... Python is really nice for this stuff... Piece a cake.. now I just need to stuff it in some dictionary and I am done or so ;) Though a dictionary might be hard to traverse in sequence... A list is probably enough... assuming no duplicate entries for now... And done ;) =D Bye, Skybuck.
[toc] | [prev] | [next] | [standalone]
| From | Steven D'Aprano <steve@pearwood.info> |
|---|---|
| Date | 2015-06-05 03:14 +1000 |
| Message-ID | <55708764$0$13011$c3e8da3$5496439d@news.astraweb.com> |
| In reply to | #92067 |
On Fri, 5 Jun 2015 03:02 am, Skybuck Flying wrote: > Yeah... my first nice parser for this kind of stuff... > > Python is really nice for this stuff... > > Piece a cake.. now I just need to stuff it in some dictionary and I am > done or so ;) > > Though a dictionary might be hard to traverse in sequence... Use an ordered dict: from collections import OrderedDict -- Steven
[toc] | [prev] | [next] | [standalone]
Page 2 of 3 — ← Prev page 1 [2] 3 Next page →
Back to top | Article view | comp.lang.python
csiph-web