Python Forum
mysql search for needle
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
mysql search for needle
#4
Quote:Shouldnt there be FROM when table is referenced?

Doh I thought i had it at one point. Must of twisted the commands

So here is one post given from the command
SELECT * FROM phpbb_posts;
Quote:having trouble reading a binary file                                                    | Hello there!
Brand new to the forum, and to Python. As background... I have not coded in *years*, since my amiga days! Wanted to get back into coding, especially games, and after some research decided that Python and Pygame are the way to go.

Anyway, this has me stumped...

For a simple game (just to get me back in the habit), I have created a 'map' using 'tile studio', which it saves maps as raw binary files; i.e. lists of numbers corresponding to a tile. Unfortunately, as I have slightly over 256 different tiles, they are stored as words (doubles).

The best code I could come up with to read this file is this...

[code:2ig6rwl4]metromap=[]
metrofile=open('metromap.bin','r')
for f in range(0,2239):
   code=0
   s=metrofile.read(1)
   if len(s)>0:
       code=ord(s)
   s=metrofile.read(1)
   if len(s)>0:
       code+=ord(s)*256
   metromap.append(code)    
metrofile.close()
print metromap  # just for debug purposes  [/code:2ig6rwl4]

Sorry for 'f' but I am a BASIC programmer at heart!

The file is 4480 bytes long. The problem occurs at the 2040th byte (i.e. f=1020)

Suddenly it doesn't want to read the rest of the file. As the forum does not allow .bin files to be attached (I tried renaming it to .jpg, but it saw right through that ruse!), I have *attempted* to include the 'bin' code below. I can supply the file to anyone curious. The next four words after the problem are '1', '2' and '3', but surely that is coincidence!

Everything up until that point is fine. I have tried various permutations of the above code. The most obvious, using the 'rb' flag on the 'open' statement and ignoring strings (I like strings!), causes python to lock up at that point. Removing the 'if len(s)' condition, causes an exception:

[code:2ig6rwl4]ord() expected a character, but string of length 0 found[/code:2ig6rwl4]

Something is happening here that my stupid brain doesn't understand... any help would be much appreciated! S

and if I search for BASIC it comes up dry
mysql> SELECT * FROM phpbb_posts WHERE post_text LIKE '%$BASIC%';
Empty set (0.82 sec)
mysql> SELECT * FROM phpbb_posts WHERE post_text LIKE '%$\bBASIC\b%';
Empty set (0.82 sec)
mysql> 
Recommended Tutorials:
Reply


Messages In This Thread
mysql search for needle - by metulburr - Apr-16-2017, 08:13 AM
RE: mysql search for needle - by zivoni - Apr-16-2017, 09:28 AM
RE: mysql search for needle - by ichabod801 - Apr-16-2017, 10:15 AM
RE: mysql search for needle - by metulburr - Apr-16-2017, 11:56 AM
RE: mysql search for needle - by zivoni - Apr-16-2017, 12:01 PM
RE: mysql search for needle - by metulburr - Apr-16-2017, 12:06 PM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020