Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Locked thread
taqueso
Mar 8, 2004


:911:
:wookie: :thermidor: :wookie:
:dehumanize:

:pirate::hf::tinfoil:

Capnbigboobies posted:

Edit: also http://www.pyside.org/docs/pyside/contents.html
Thats what I was looking for. Thanks

Adbot
ADBOT LOVES YOU

ufarn
May 30, 2009
Has anyone in here created a blog using the Blogofile framework from start to finish? I am so close to finalizing my blog, but pagination is completely abstruse without any shred of useful documentation.

The prospect of having a blog that's completely static motivates me to keep pressing on, though.

nonathlon
Jul 9, 2004
And yet, somehow, now it's my fault ...
A sprawling open-ended question: I was using Plone for my personal website for many years. Can't say it was a great experience but it's a powerful system and when it worked, it was great. But now I've fled my (managed) site host for by own machine at Linode, and was wondering whether I should look at another CMS.

Stuff I like / want:

- Python based: for when I have to debug it and also when I have to occasionally write some custom stuff.
- Humane / understandable nested urls: e.g http://www.outlier.me/work/biology/2011
- A decent selection of themes: because I have no artistic talent

Pinax? Any other Python-centric CMS?

Haystack
Jan 23, 2005





Take a look at Kotti. It doesn't offer a lot in the way of fluff, but it has as about as solid a foundation you could hope for.

duck monster
Dec 15, 2004

Is pyside or pyqt something that actually works with Lion and the new QT yet?

duck monster
Dec 15, 2004

outlier posted:

A sprawling open-ended question: I was using Plone for my personal website for many years. Can't say it was a great experience but it's a powerful system and when it worked, it was great. But now I've fled my (managed) site host for by own machine at Linode, and was wondering whether I should look at another CMS.

Stuff I like / want:

- Python based: for when I have to debug it and also when I have to occasionally write some custom stuff.
- Humane / understandable nested urls: e.g http://www.outlier.me/work/biology/2011
- A decent selection of themes: because I have no artistic talent

Pinax? Any other Python-centric CMS?

Plone was, and I'd argue still is, a great solution for big corporate or government websites where there is going to be a shitload of content and a need for a well defined workflow. I couldn't imagine torturing myself for using it with a personal website and a blog though.

Although heck, these days, for big coprorate or govt websites, I'd probably use Alfresco as a back end, if not just to try and ingrain myself deeper into the company with a lucrative business process contract (Ie "making the company your bitch") and build the front end with Django and some sort of CMS that handles CMIS

nonathlon
Jul 9, 2004
And yet, somehow, now it's my fault ...

Haystack posted:

Take a look at Kotti. It doesn't offer a lot in the way of fluff, but it has as about as solid a foundation you could hope for.

Hadn't heard of this before - I'll look into it. I see it's using Pyramid, which I've been interested in for a while.

duck monster posted:

(Plone) I couldn't imagine torturing myself for using it with a personal website and a blog though.

Don't I know it. I've lost months of my life wrangling that shambling beast of a thing. But at the time I adopted it, there weren't a lot of choices and the Plone koolaid was very persuasive.

Which leads me to another question: I need to write readers for a few bioinformatic formats I have to work with. Actually I have already written a few of these readers by hand, which was about as fun as expected. So I was considering going with a proper, third party parsing library. The code would initially be for my own use, but I certainly have an eye on redistribution and wider use, which means the external library has to be ... reliable. No crappy installs, would like it to have some longevity.

Pyparsing is the obvious choice. But I'm uneasy with the way it reads a whole file in at once. Are there strong competitors? I've found nothing but a lot of one-man projects.

nonathlon fucked around with this message at 16:31 on Jan 9, 2012

Maluco Marinero
Jan 18, 2001

Damn that's a
fine elephant.
Amateur programmer here. Been reading about Design by Contract lately and I feel like it's a real elegant method of guaranteeing and checking for specifics in your documentation in one fell swoop, especially when coupled with other testing to fill the gaps invariant, pre and post can't do. I was gonna try and use the implementation written for PEP 316 -
http://www.wayforward.net/pycontract/ - and was wondering if anyone had some experience with it. Mainly looking to see if anyone had a horrible time with it and would recommend against it.

duck monster
Dec 15, 2004

outlier posted:

Hadn't heard of this before - I'll look into it. I see it's using Pyramid, which I've been interested in for a while.


Don't I know it. I've lost months of my life wrangling that shambling beast of a thing. But at the time I adopted it, there weren't a lot of choices and the Plone koolaid was very persuasive.

Which leads me to another question: I need to write readers for a few bioinformatic formats I have to work with. Actually I have already written a few of these readers by hand, which was about as fun as expected. So I was considering going with a proper, third party parsing library. The code would initially be for my own use, but I certainly have an eye on redistribution and wider use, which means the external library has to be ... reliable. No crappy installs, would like it to have some longevity.

Pyparsing is the obvious choice. But I'm uneasy with the way it reads a whole file in at once. Are there strong competitors? I've found nothing but a lot of one-man projects.

Is it a binary or xml type format?

Haystack
Jan 23, 2005





Check out Lepl

nonathlon
Jul 9, 2004
And yet, somehow, now it's my fault ...

duck monster posted:

Is it a binary or xml type format?

Plaintext. Good old "I'll invent a format myself" plaintext.

Zombywuf
Mar 29, 2008

outlier posted:

Plaintext. Good old "I'll invent a format myself" plaintext.

fasta? http://www2.warwick.ac.uk/fac/sci/moac/people/students/peter_cock/python/fasta_n/

nonathlon
Jul 9, 2004
And yet, somehow, now it's my fault ...

God, no. Were it that simple. I'd just use BioPython.

I've got a bunch of semi-obscure phylogeny programs (no names, don't want to get in trouble) that write their results in their own plaintext formats. As far as these things go, they're not too bad - they have clearly marked sections and named fields - but they're still sufficiently unlike anything else that a custom parse is necessary. The trees themselves aren't too bad, except they annotate internal nodes in peculiar ways, so that has to be interpreted correctly. I'd like to process a whole bunch of these files into a more sane format, i.e. one that can be used by other programs, and vice versa. So again a custom parse is required.

ufarn
May 30, 2009
I am using a Python blogging CMS called Blogofile. The CMS uses a YAML header where the database layer is posted, including the title of the post. My problem is that I can't write blog titles with quotes around them, so a title like "The dog hasn't pooped on the lawn; it wasn't him" turns into the same. With Blogofile/Python/YAML, instead, the quotes are removed by the parser and taken to just mean that the title is a string, so I get The dog hasn't pooped on the lawn; it wasn't him.

I tried wrapping the double quotes with single quotes, but this clashes with the apostrophe quotes inside the title and gives me this:

code:
File "C:\Python27\lib\site-packages\yaml\parser.py", line 439, in parse_block_mapping_key
  "expected <block end>, but found %r" % token.id, token.start_mark)
ml.parser.ParserError: while parsing a block mapping
in "<unicode string>", line 2, column 1:
I thought about just escaping the quotes, but escaping them means that my SmartyPants script also escapes the quotes and does not render them according to its typographic purpose.

Do you have any suggestions about how I could render a quote article the way I want to?

The Gripper
Sep 14, 2004
i am winner

ufarn posted:

I am using a Python blogging CMS called Blogofile. The CMS uses a YAML header where the database layer is posted, including the title of the post. My problem is that I can't write blog titles with quotes around them, so a title like "The dog hasn't pooped on the lawn; it wasn't him" turns into the same. With Blogofile/Python/YAML, instead, the quotes are removed by the parser and taken to just mean that the title is a string, so I get The dog hasn't pooped on the lawn; it wasn't him.

I tried wrapping the double quotes with single quotes, but this clashes with the apostrophe quotes inside the title and gives me this:

code:
File "C:\Python27\lib\site-packages\yaml\parser.py", line 439, in parse_block_mapping_key
  "expected <block end>, but found %r" % token.id, token.start_mark)
ml.parser.ParserError: while parsing a block mapping
in "<unicode string>", line 2, column 1:
I thought about just escaping the quotes, but escaping them means that my SmartyPants script also escapes the quotes and does not render them according to its typographic purpose.

Do you have any suggestions about how I could render a quote article the way I want to?
You could enclose the string in triple-quotes, e.g.
code:
Python 2.7.2 (default, Jun 12 2011, 15:08:59) [MSC v.1500 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> n = """he"llo"""
>>> n
'he"llo'
>>>
I'm not sure about how Blogofile is handling the strings itself, but triple-quotes should allow embedded quotes in strings without issue in most cases.

Edit; re-reading it I think I misunderstood, I'm not sure what you can do to fix that if you're just entering it into the CMS pages, unless what I suggested above actually works.

The Gripper fucked around with this message at 14:22 on Jan 10, 2012

ufarn
May 30, 2009

The Gripper posted:

You could enclose the string in triple-quotes, e.g.
code:
Python 2.7.2 (default, Jun 12 2011, 15:08:59) [MSC v.1500 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> n = """he"llo"""
>>> n
'he"llo'
>>>
I'm not sure about how Blogofile is handling the strings itself, but triple-quotes should allow embedded quotes in strings without issue in most cases.

Edit; re-reading it I think I misunderstood, I'm not sure what you can do to fix that if you're just entering it into the CMS pages, unless what I suggested above actually works.
Yeah, I tried the triple quotes, but Python/YAML/Blogofile doesn't seem to support it. It's worth mentioning that this is a somewhat broken CMS by default that needs some tweaks to begin with, so I am not surprised.

As for how the data is entered, it's a .markdown document with a YAML header like so

code:
---
title: So-and-so
date:  2010/08/08 05:05:00
custom_field: Derp
---
And this is the content of the actual blog post.
I assume the fields are parsed first by a YAML parser, and then Python, considering that the error happens at C:\Python27\lib\site-packages\yaml\parser.py.

I guess I'll just have to eschew the wrapping quotes for the time being or create a boolean is_quote field to wrap quotes around the title.

The Gripper
Sep 14, 2004
i am winner

ufarn posted:

Yeah, I tried the triple quotes, but Python/YAML/Blogofile doesn't seem to support it. It's worth mentioning that this is a somewhat broken CMS by default that needs some tweaks to begin with, so I am not surprised.

As for how the data is entered, it's a .markdown document with a YAML header like so

code:
---
title: So-and-so
date:  2010/08/08 05:05:00
custom_field: Derp
---
And this is the content of the actual blog post.
I assume the fields are parsed first by a YAML parser, and then Python, considering that the error happens at C:\Python27\lib\site-packages\yaml\parser.py.

I guess I'll just have to eschew the wrapping quotes for the time being or create a boolean is_quote field to wrap quotes around the title.
That's fairly lovely, having the CMS parse it again seems like it'd be removing one of the handy features of YAML outright. Does it remove any escape sequences when you enter it? You could try "This is a \x22Test\x22" which would unescape to This is a "Test", but if "This is a \"Test\"" doesn't work then this might not either.

ufarn
May 30, 2009

The Gripper posted:

That's fairly lovely, having the CMS parse it again seems like it'd be removing one of the handy features of YAML outright. Does it remove any escape sequences when you enter it? You could try "This is a \x22Test\x22" which would unescape to This is a "Test", but if "This is a \"Test\"" doesn't work then this might not either.
Wrapping my title in "\x22 foo \x22" makes the quotes work, so I guess I can always go with that.

It just feels like too many chefs are involved in the parsing of the title, but at least I have a way to display it now.

(Also, thanks.)

ufarn fucked around with this message at 15:37 on Jan 10, 2012

tef
May 30, 2004

-> some l-system crap ->

quote:

Which leads me to another question: I need to write readers for a few bioinformatic formats I have to work with.

Yay. Parsing.

:unsmith:

outlier posted:

Plaintext. Good old "I'll invent a format myself" plaintext.

Oh.
:smith:

You're hosed for parsing libraries in general - most handwritten formats don't fit well into LL(n)/LR(n) grammars, and are frequently unnameable to (unambiguous) tokenization. Unless the language was designed with a parser in mind, it is frequently easier to hand-roll the parser over hand-bodge the parser library/tools.

If the files are very small, you might get far with a packrat parser (what with it being scannerless), and there are some recursive descent libraries for python that may help more than hinder you too. Packrat parsing is backtracking + memorisation over a recursive descent parse, so it has a bounded runtime, but /heavy/ memory requirements.

Stream parsing support is generally quite poor in libraries, if you need it you're forced to hand write bits.

outlier posted:

Pyparsing is the obvious choice. But I'm uneasy with the way it reads a whole file in at once. Are there strong competitors? I've found nothing but a lot of one-man projects.


Oh, large files too?.

:smithicide:

If you want to use a library and want to avoid reading the file at a time, my suggestion would be *mutliple* layers of tokenization (effectively).

If your format is block orientated (i.e if it's a bunch of records concatenated together), you can pull the blocks out of the file one at a time, before passing that string to a parsing library. (i'd look at packrat/pegs)


I hope your format is block orientated

:unsmith:

tef
May 30, 2004

-> some l-system crap ->

duck monster posted:

Is pyside or pyqt something that actually works with Lion and the new QT yet?

I am testing this today. I will post a trip report.

edit: sip installs, qt installs, pyqt 4.9 bugs out and dies in qtnetwork on an ssl error

edit: previously forgotten qt installation is loving things up. joy

tef fucked around with this message at 18:11 on Jan 10, 2012

Winkle-Daddy
Mar 10, 2007
So, I recently started picking up Panda3D for use with Python as I like making games. I'm building a first person shooter that has a minecraft-like terrain generator. I am using a perlin noise function to generate my terrain and it creates a float value between 0 and 1. I'm hitting a bottleneck on how much geometry I can load into the scene at once because I currently have to load the entirety of the terrain into memory. I want to knock that poo poo off and use a flat file or database instead.

The problem with just using a flat file (via, say, pickle for example) is that if I create a world that is 500blocks x 500blocks x 50blocks, then my pkl file is nearly 400mb in size. To read back out of this, I experience a considerable amount of delay while I open the file to load it into memory and the game freezes each time I load and unload the external file.

I began thinking about using MySQL as that solves almost all of my problems. I can look up a specific x,y,z value extremely quickly. However, I plan on doing a py -> exe when this is done and I don't want the end user to have to install and configure a MySQL database for a game. I began looking for some nosql solutions but it seems there are a lot out there, so I figured I would ask what others would suggest based on the following requirements:

- Create a flat file that requires no 3rd party database service to be running on the end user's computer (like I would with MySQL)
- Create small-ish flat files (under 100mb each)
- Have indexing or a method of looking up values without having to load the entire file into memory.

Any suggestions on anything that might suit my needs?

tef
May 30, 2004

-> some l-system crap ->
sqlite3 is built in

Winkle-Daddy
Mar 10, 2007
Awesome! This sounds exactly like what I'm looking for!

"sqlite page' posted:

SQLite is a C library that provides a lightweight disk-based database that doesn’t require a separate server process and allows accessing the database using a nonstandard variant of the SQL query language. Some applications can use SQLite for internal data storage. It’s also possible to prototype an application using SQLite and then port the code to a larger database such as PostgreSQL or Oracle.

tef
May 30, 2004

-> some l-system crap ->
There are some notable things that can trip you up in sqlite3 - unicode handling (everything str becomes unicode so use BLOBs or conn.text_factory=str), auto-commit shenanigans (controllable with isolation_level=None), and those bits where you pass in a string instead of a one element tuple of a string i.e. ("foo",) vs ("foo")

tef
May 30, 2004

-> some l-system crap ->

tef posted:

I am testing this today. I will post a trip report.

edit: sip installs, qt installs, pyqt 4.9 bugs out and dies in qtnetwork on an ssl error

edit: previously forgotten qt installation is loving things up. joy

continued:

after cleaning everything up and installing the prepackaged qt sdk from the website into /Developer/Qt
pyqt behaved when configured thus: python configure.py -q /Developer/Qt/Desktop/Qt/474/gcc/bin/qmake -k

but now I have a PyQt4 but no PyQt4.QtGui :confused:. I think i'm going to have to build qt from source. :smithicide:

duck monster
Dec 15, 2004

Winkle-Daddy posted:

So, I recently started picking up Panda3D for use with Python as I like making games. I'm building a first person shooter that has a minecraft-like terrain generator. I am using a perlin noise function to generate my terrain and it creates a float value between 0 and 1. I'm hitting a bottleneck on how much geometry I can load into the scene at once because I currently have to load the entirety of the terrain into memory. I want to knock that poo poo off and use a flat file or database instead.

The problem with just using a flat file (via, say, pickle for example) is that if I create a world that is 500blocks x 500blocks x 50blocks, then my pkl file is nearly 400mb in size. To read back out of this, I experience a considerable amount of delay while I open the file to load it into memory and the game freezes each time I load and unload the external file.

I began thinking about using MySQL as that solves almost all of my problems. I can look up a specific x,y,z value extremely quickly. However, I plan on doing a py -> exe when this is done and I don't want the end user to have to install and configure a MySQL database for a game. I began looking for some nosql solutions but it seems there are a lot out there, so I figured I would ask what others would suggest based on the following requirements:

- Create a flat file that requires no 3rd party database service to be running on the end user's computer (like I would with MySQL)
- Create small-ish flat files (under 100mb each)
- Have indexing or a method of looking up values without having to load the entire file into memory.

Any suggestions on anything that might suit my needs?

How are you going about culling? In theory you could maybe use some sort of sparse octree boxel thingo to compress the crap out of the data by culling self-similar nodes into a higher representation or whatever, if that makes any sense, that also removes a tonne of strain from your renderer , because theres a lot less backfaces etc to worry about rendering. I'm currently very obsessed with these octree things. They are super neato structures.

e: Oh yeah, and keep in mind how Minecraft does it by just loading and unloading nearby chunks as need be.

duck monster fucked around with this message at 20:19 on Jan 10, 2012

Winkle-Daddy
Mar 10, 2007
^^^ Yeah, I'm building 4x4x4 chunks and will load/unload them based on the players current position. At least, that's the theory once I get the chunk generator working :)

tef posted:

There are some notable things that can trip you up in sqlite3 - unicode handling (everything str becomes unicode so use BLOBs or conn.text_factory=str), auto-commit shenanigans (controllable with isolation_level=None), and those bits where you pass in a string instead of a one element tuple of a string i.e. ("foo",) vs ("foo")

Hmmm, I'm having some issues as a total python and sqlite noob. Here's my code:

code:
class createWorld():
	def __init__(self):
		self.world = PerlinNoise3(30,30,10,128,11)
		
	def dbCreate(self,level):
		self.connect = sqlite3.connect(level)
		self.cursor = self.connect.cursor()
		self.cursor.execute('''create table chunks (chunkid real, x real, y real, z real, val real)''')
		self.connect.commit()
		self.connect.close()
		
	def dbChunk(self,level,chunk):
		self.vals = {}
		self.connect = sqlite3.connect(level)
		self.cursor = self.connect.cursor()
		for x in range (0,4):
			self.vals[x] = {}
			for y in range (0,4):
				self.vals[x][y] = {}
				for z in range (0,4):
					if self.world(x,y,z) >= 0.22:
						self.vals[x][y][z] = 1
					else:
						self.vals[x][y][z] = 0
					self.cursor.execute('insert into chunks values (?, ?, ?, ?, ?)',(chunk,x,y,z,self.vals[x][y][z]))
		self.connect.commit()
		self.connect.close()
		
	def getWorld(self,level,chunk,x,y,z):
		self.connect = sqlite3.connect(level)
		self.cursor = self.connect.cursor()
		self.value = self.cursor.execute('select val from chunks where chunkid = ? and x = ? and y = ? and z = ?',(chunk,x,y,z))
		return self.value
		self.connect.close()
However, when I print the value returned by getWorld, the result is:

code:
<sqlite3.Cursor object at 0x13e937a0>
<sqlite3.Cursor object at 0x13e93710>
<sqlite3.Cursor object at 0x13e93830>
<sqlite3.Cursor object at 0x13e93890>
<sqlite3.Cursor object at 0x13e938f0>
<sqlite3.Cursor object at 0x13e93950>
<sqlite3.Cursor object at 0x13e939b0>
<sqlite3.Cursor object at 0x13e93a10>
<sqlite3.Cursor object at 0x13e93a70>
<sqlite3.Cursor object at 0x13e93ad0>
<sqlite3.Cursor object at 0x13e93b30>
<sqlite3.Cursor object at 0x13e93b90>
...and so on...
I'm sure it's something stupid, like de-referencing in Perl. But y'know...I'm new to this. It's really cool so far, though!

tef
May 30, 2004

-> some l-system crap ->
Use cursor.fetchone()/ cursor.fetchall():

Winkle-Daddy
Mar 10, 2007
Thanks! I knew it was something dumb. :downs:

e: God I love Python:



edit 2: I'm getting a weird error, 'TypeError: 'NoneType' object is unsubscriptable'

I think this is happening because the DB inserts haven't finished before I try building the next chunk. Does that sound about right? Is there an easy way to assure it's finished building?

edit 3: Nope, I was wrong, that has nothing to do with it. I'll try to figure out how to solve this on my own, otherwise it'll be a massive code dump.

Winkle-Daddy fucked around with this message at 00:12 on Jan 11, 2012

nonathlon
Jul 9, 2004
And yet, somehow, now it's my fault ...

tef posted:

If you want to use a library and want to avoid reading the file at a time, my suggestion would be *mutliple* layers of tokenization (effectively).

Good suggestion. The packrat stuff is new to me, so I'll explore that.

quote:

I hope your format is block orientated

:unsmith:

Formats. And they are. Kind of ...

Winkle-Daddy
Mar 10, 2007
I'm having some more sqlite and python issues. Hopefully this is an easy one!

code:
	def getWorld(self,level,chunk,x,y,z):
		self.connect = sqlite3.connect(level)
		self.cursor = self.connect.cursor()
		self.cursor.execute('select val from chunks where chunkid = ? and x = ? and y = ? and z = ?',(chunk,x,y,z))
		self.value = self.cursor.fetchone()[0]
		
		#self.cursor1 = self.connect.cursor()
		self.cursor.execute('select val from chunks where chunkid = ? and x = ? and y = ? and z = ?',(chunk,x-1,y,z))
		self.xm = self.cursor.fetchone()[0]
		print(self.xm)
		if self.xm is None:
			self.xm = 0
		
		#self.cursor2 = self.connect.cursor()
		self.cursor.execute('select val from chunks where chunkid = ? and x = ? and y = ? and z = ?',(chunk,x+1,y,z))
		self.xp = self.cursor.fetchone()[0]
		if self.xp is None:
			self.xp = 0
			
		#self.cursor3 = self.connect.cursor()
		self.cursor.execute('select val from chunks where chunkid = ? and x = ? and y = ? and z = ?',(chunk,x,y-1,z))
		self.ym = self.cursor.fetchone()[0]
		if self.ym is None:
			self.ym = 0
		
		#self.cursor4 = self.connect.cursor()
		self.cursor.execute('select val from chunks where chunkid = ? and x = ? and y = ? and z = ?',(chunk,x,y+1,z))
		self.yp = self.cursor.fetchone()[0]
		if self.yp is None:
			self.yp = 0
		
		#self.cursor5 = self.connect.cursor()
		self.cursor.execute('select val from chunks where chunkid = ? and x = ? and y = ? and z = ?',(chunk,x,y,z-1))
		self.zm = self.cursor.fetchone()[0]
		if self.zm is None:
			self.zm = 0
		
		#self.cursor6 = self.connect.cursor()
		self.cursor.execute('select val from chunks where chunkid = ? and x = ? and y = ? and z = ?',(chunk,x,y,z+1))
		self.zp = self.cursor.fetchone()[0]
		if self.zp is None:
			self.zp = 0
		
		if(self.xm != '1' or self.xp != '1' or self.ym != '1' or self.yp != '1' or self.zm != '1' or self.zp != '1'):
			return self.value
		else:
			return 0
		self.connect.close()
Returns:

self.xm = self.cursor.fetchone()[0]
TypeError: 'NoneType' object is unsubscriptable

I assume it's because a null value is being returned, but I thought 'None' was the keyword to catch that exception?

edit: Maybe I'm not able to reuse the cursor like that?

Winkle-Daddy fucked around with this message at 18:48 on Jan 11, 2012

tef
May 30, 2004

-> some l-system crap ->
It's None or a Tuple that fetchone() returns. You are doing fetchone()[0] to get the first element of the tuple.

You should be doing x=....fetchone(); if x is not None: blah =x[0] ....

tef
May 30, 2004

-> some l-system crap ->

tef posted:

continued:

after cleaning everything up and installing the prepackaged qt sdk from the website into /Developer/Qt
pyqt behaved when configured thus: python configure.py -q /Developer/Qt/Desktop/Qt/474/gcc/bin/qmake -k

but now I have a PyQt4 but no PyQt4.QtGui :confused:. I think i'm going to have to build qt from source. :smithicide:

works now :3:

so that's install sip with python configure.py; make etc
install qt somewhere using the prepackaged installer, and
python configure.py -q /Developer/Qt/Desktop/Qt/474/gcc/bin/qmake -g , etc for pyqt.

Winkle-Daddy
Mar 10, 2007

tef posted:

It's None or a Tuple that fetchone() returns. You are doing fetchone()[0] to get the first element of the tuple.

You should be doing x=....fetchone(); if x is not None: blah =x[0] ....

Awesome, thanks! (God, I'm missing PHP right now)

tef
May 30, 2004

-> some l-system crap ->

Winkle-Daddy posted:

Awesome, thanks! (God, I'm missing PHP right now)

Well you wouldn't have been able to do function_call()[0] in php so I can see how the power may be a little overwhelming :3:

Winkle-Daddy
Mar 10, 2007

tef posted:

Well you wouldn't have been able to do function_call()[0] in php so I can see how the power may be a little overwhelming :3:

Hmmm, so based on your advice, I rewrote my function to look like this:
code:
		self.cursor.execute('select val from chunks where chunkid = ? and x = ? and y = ? and z = ?',(chunk,x-1,y,z))
		if self.cursor.fetchone() is None:
			self.xm = 0
		else:
			self.xm = self.cursor.fetchone()[0]
		
		self.cursor.execute('select val from chunks where chunkid = ? and x = ? and y = ? and z = ?',(chunk,x+1,y,z))
		if self.cursor.fetchone() is None:
			self.xp = 0
		else:
			self.xp = self.cursor.fetchone()[0]
I'm still getting the TypeError: 'NoneType' object is unsusbscriptable. But this time for self.xp. The code between the two sections is identical, right? I'm not crazy and missing something? Do I have to use a unique cursor for each execute? (I don't think that would make sense...)

Thermopyle
Jul 1, 2003

...the stupid are cocksure while the intelligent are full of doubt. —Bertrand Russell

Winkle-Daddy posted:

Hmmm, so based on your advice, I rewrote my function to look like this:
code:
		self.cursor.execute('select val from chunks where chunkid = ? and x = ? and y = ? and z = ?',(chunk,x-1,y,z))
		if self.cursor.fetchone() is None:
			self.xm = 0
		else:
			self.xm = self.cursor.fetchone()[0]
		
		self.cursor.execute('select val from chunks where chunkid = ? and x = ? and y = ? and z = ?',(chunk,x+1,y,z))
		if self.cursor.fetchone() is None:
			self.xp = 0
		else:
			self.xp = self.cursor.fetchone()[0]
I'm still getting the TypeError: 'NoneType' object is unsusbscriptable. But this time for self.xp. The code between the two sections is identical, right? I'm not crazy and missing something? Do I have to use a unique cursor for each execute? (I don't think that would make sense...)

It's been awhile since I messed with this, but each time you call fetchone() it advances to the next row in the db.

So...

On this line:

code:
if self.cursor.fetchone() is None:
The cursor returns a row to the if statement and advances to the next row. If it's at the last row then when you get to this line:

code:
self.xp = self.cursor.fetchone()[0]
It's at the end of your rows and doesn't have anything to return so it returns None. You can't subscript None with [0].

To fix this, at the beginning assign self.cursor.fetchone() to a variable and then test that variable for None-ness.

Thermopyle fucked around with this message at 19:35 on Jan 11, 2012

Winkle-Daddy
Mar 10, 2007
Since I'm not wanting to increment but save the result of my query to a variable each time, can I get around this by declaring a new cursor variable each time?

e.g.

code:
self.cursor1 = self.connect.cursor()
self.cursor1.execute('select val from chunks where chunkid = ? and x = ? and y = ? and z = ?',(chunk,x+1,y,z))
		if self.cursor1.fetchone() is None:
			self.xp = 0
		else:
			self.xp = self.cursor1.fetchone()[0]
?

Nippashish
Nov 2, 2005

Let me see you dance!

Winkle-Daddy posted:

Since I'm not wanting to increment but save the result of my query to a variable each time, can I get around this by declaring a new cursor variable each time?

Have you considered saving the result of your query to a variable each time instead?

Adbot
ADBOT LOVES YOU

tef
May 30, 2004

-> some l-system crap ->

Winkle-Daddy posted:

Hmmm, so based on your advice

to be clearer

code:
row = self.cursor.fetchone()
if row is None:
	self.xm = 0
else:
	self.xm = row[0]

  • Locked thread