473,804 Members | 2,007 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

visual indentation

Hello,

I'm using python to output RIB streams for Renderman.
The RIB stream is a bunch of statements which describes
a 3d image. The Rib standard allows for blocks which we
usually indent for better visualization for example:

WorldBegin
Color [1 1 1]
Surface "constant"
Sphere(1.0, -1.0, 1.0, 360)
WorldEnd

I'm using CGKit in python which has a Renderman binding,
so to output the same RIB I'd write:

RiWorldBegin()
RiColor(1.0,1.0 ,1.0)
RiSurface('cons tant')
RiSphere(1.0,-1.0,1.0,360)
RiWorldEnd()

But I get an error, because python interprets my indentation
as a block in the python code. So the only way to write this
is without the indentation:

RiWorldBegin()
RiColor(1.0,1.0 ,1.0)
RiSurface('cons tant')
RiSphere(1.0,-1.0,1.0,360)
RiWorldEnd()

But this is a lot harder to read.

Is there any way to use such "visual" indentation in python?

Thanks,
Hilbert

hi*****@panka.c om
Jul 18 '05 #1
15 2149
Hilbert wrote:

Hello,

I'm using python to output RIB streams for Renderman.
The RIB stream is a bunch of statements which describes
a 3d image. The Rib standard allows for blocks which we
usually indent for better visualization for example:

WorldBegin
Color [1 1 1]
Surface "constant"
Sphere(1.0, -1.0, 1.0, 360)
WorldEnd

I'm using CGKit in python which has a Renderman binding,
so to output the same RIB I'd write:

RiWorldBegin()
RiColor(1.0,1.0 ,1.0)
RiSurface('cons tant')
RiSphere(1.0,-1.0,1.0,360)
RiWorldEnd()

But I get an error, because python interprets my indentation
as a block in the python code. So the only way to write this
is without the indentation:

RiWorldBegin()
RiColor(1.0,1.0 ,1.0)
RiSurface('cons tant')
RiSphere(1.0,-1.0,1.0,360)
RiWorldEnd()

But this is a lot harder to read.

Is there any way to use such "visual" indentation in python?


If the code is purely sequential, how about something like this:

import string
def RunTheseStateme nts(s):
stmts = map(string.stri p, s.split("\n"))
for stmt in stmts:
eval(stmt)

RunTheseStateme nts("""
RiWorldBegin()
RiColor(1.0,1.0 ,1.0)
RiSurface('cons tant')
RiSphere(1.0,-1.0,1.0,360)
RiWorldEnd()
""")
Al
Jul 18 '05 #2
Hilbert wrote:
Is there any way to use such "visual" indentation in python?


Whitespace *is* significant in Python, and you should not try to circumvent
this using dirty tricks. Why not structuring your world definitions in the
standard way, putting the things that belong together in separate functions
or classes?

#disclaimer: no knowledge of CGKit involved in the following code
WHITE = (1.0,1.0,1.0)

def whitesurface():
RiColor(*WHITE)
RiSurface('cons tant')

def firstworld():
whitesurface()
RiSphere(1.0,-1.0,1.0,360)

def secondworld():
whitesurface()
RiSphere(1.0,-1.0,1.0,360)

for world in [firstworld, secondworld]:
RiWorldBegin()
world()
RiWorldEnd()

I think the above is pretty readable, and you can always factor out
repeating chunks of code

Peter
Jul 18 '05 #3

"Hilbert" <Hi*****@panka. com> wrote in message
news:sl******** ************@se rver.panka.com. ..
Hello,

I'm using python to output RIB streams for Renderman.
The RIB stream is a bunch of statements which describes
a 3d image. The Rib standard allows for blocks which we
usually indent for better visualization for example:

WorldBegin
Color [1 1 1]
Surface "constant"
Sphere(1.0, -1.0, 1.0, 360)
WorldEnd

I'm using CGKit in python which has a Renderman binding,
so to output the same RIB I'd write:

RiWorldBegin()
RiColor(1.0,1.0 ,1.0)
RiSurface('cons tant')
RiSphere(1.0,-1.0,1.0,360)
RiWorldEnd()

But I get an error, because python interprets my indentation
as a block in the python code. So the only way to write this
is without the indentation:

RiWorldBegin()
RiColor(1.0,1.0 ,1.0)
RiSurface('cons tant')
RiSphere(1.0,-1.0,1.0,360)
RiWorldEnd()

But this is a lot harder to read.

Is there any way to use such "visual" indentation in python?

Thanks,
Hilbert

hi*****@panka.c om


What about an if statement:

RiWorldBegin()
if True:
RiColor(1.0,1.0 ,1.0)
RiSurface('cons tant')
RiSphere(1.0,-1.0,1.0,360)
RiWorldEnd()

I realize it's ugly, but it's easy.
Jul 18 '05 #4
On Friday 22 August 2003 11:28 am, ac*****@easystr eet.com wrote:
Hilbert wrote:
Hello,

I'm using python to output RIB streams for Renderman.
The RIB stream is a bunch of statements which describes
a 3d image. The Rib standard allows for blocks which we
usually indent for better visualization for example:

WorldBegin
Color [1 1 1]
Surface "constant"
Sphere(1.0, -1.0, 1.0, 360)
WorldEnd

I'm using CGKit in python which has a Renderman binding,
so to output the same RIB I'd write:

RiWorldBegin()
RiColor(1.0,1.0 ,1.0)
RiSurface('cons tant')
RiSphere(1.0,-1.0,1.0,360)
RiWorldEnd()

But I get an error, because python interprets my indentation
as a block in the python code. So the only way to write this
is without the indentation:

RiWorldBegin()
RiColor(1.0,1.0 ,1.0)
RiSurface('cons tant')
RiSphere(1.0,-1.0,1.0,360)
RiWorldEnd()

But this is a lot harder to read.

Is there any way to use such "visual" indentation in python?


If the code is purely sequential, how about something like this:

import string
def RunTheseStateme nts(s):
stmts = map(string.stri p, s.split("\n"))
for stmt in stmts:
eval(stmt)

RunTheseStateme nts("""
RiWorldBegin()
RiColor(1.0,1.0 ,1.0)
RiSurface('cons tant')
RiSphere(1.0,-1.0,1.0,360)
RiWorldEnd()
""")


Here's another way -- inside a [..] or (...) construct

[
RiWorldBegin(),
RiColor(1.0,1.0 ,1.0),
RiSurface('cons tant'),
RiSphere(1.0,-1.0,1.0,360),
RiWorldEnd(),
]
Or try this (this might be too ugly)

RiWorldBegin()
if 1:
RiColor(1.0,1.0 ,1.0)
RiSurface('cons tant')
RiSphere(1.0,-1.0,1.0,360)
RiWorldEnd()

or make these all member functions of a class and try

c. RiWorldBegin(),
c. RiColor(1.0,1.0 ,1.0),
c. RiSurface('cons tant'),
c. RiSphere(1.0,-1.0,1.0,360),
c. RiWorldEnd(),

or

Hmmmm -- I'll bet there's more possibilities.

Gary Herron

Jul 18 '05 #5
On Fri, 22 Aug 2003 13:06:46 -0700, Gary Herron wrote:
Hmmmm -- I'll bet there's more possibilities.


All of which, like all possibilities for forcing different indentation
on Python, presented so far, *reduce* readability instead of enhancing
it.

--
\ "One time a cop pulled me over for running a stop sign. He |
`\ said, 'Didn't you see the stop sign?' I said, 'Yeah, but I |
_o__) don't believe everything I read.'" -- Steven Wright |
Ben Finney <http://bignose.squidly .org/>
Jul 18 '05 #6
On Friday 22 August 2003 11:28 am, ac*****@easystr eet.com wrote:
Hilbert wrote:
Hello,

I'm using python to output RIB streams for Renderman.
The RIB stream is a bunch of statements which describes
a 3d image. The Rib standard allows for blocks which we
usually indent for better visualization for example:

WorldBegin
Color [1 1 1]
Surface "constant"
Sphere(1.0, -1.0, 1.0, 360)
WorldEnd

I'm using CGKit in python which has a Renderman binding,
so to output the same RIB I'd write:

RiWorldBegin()
RiColor(1.0,1.0 ,1.0)
RiSurface('cons tant')
RiSphere(1.0,-1.0,1.0,360)
RiWorldEnd()

But I get an error, because python interprets my indentation
as a block in the python code. So the only way to write this
is without the indentation:

RiWorldBegin()
RiColor(1.0,1.0 ,1.0)
RiSurface('cons tant')
RiSphere(1.0,-1.0,1.0,360)
RiWorldEnd()

But this is a lot harder to read.

Is there any way to use such "visual" indentation in python?


If the code is purely sequential, how about something like this:

import string
def RunTheseStateme nts(s):
stmts = map(string.stri p, s.split("\n"))
for stmt in stmts:
eval(stmt)

RunTheseStateme nts("""
RiWorldBegin()
RiColor(1.0,1.0 ,1.0)
RiSurface('cons tant')
RiSphere(1.0,-1.0,1.0,360)
RiWorldEnd()
""")


Here's another way -- inside a [..] or (...) construct

[
RiWorldBegin(),
RiColor(1.0,1.0 ,1.0),
RiSurface('cons tant'),
RiSphere(1.0,-1.0,1.0,360),
RiWorldEnd(),
]
Or try this (this might be too ugly)

RiWorldBegin()
if 1:
RiColor(1.0,1.0 ,1.0)
RiSurface('cons tant')
RiSphere(1.0,-1.0,1.0,360)
RiWorldEnd()

or make these all member functions of a class and try

c. RiWorldBegin(),
c. RiColor(1.0,1.0 ,1.0),
c. RiSurface('cons tant'),
c. RiSphere(1.0,-1.0,1.0,360),
c. RiWorldEnd(),

or

Hmmmm -- I'll bet there's more possibilities.

Gary Herron

Jul 18 '05 #7
Hilbert <Hi*****@panka. com> wrote in message news:<sl******* *************@s erver.panka.com >...
Hello,

I'm using python to output RIB streams for Renderman.
The RIB stream is a bunch of statements which describes
a 3d image. The Rib standard allows for blocks which we
usually indent for better visualization for example:

WorldBegin
Color [1 1 1]
Surface "constant"
Sphere(1.0, -1.0, 1.0, 360)
WorldEnd .... Is there any way to use such "visual" indentation in python?


If the code consists of nothing but expressions (which yours does), you can write:

(RiWorldBegin() )
( RiColor(1.0,1.0 ,1.0))
( RiSurface('cons tant'))
( RiSphere(1.0,-1.0,1.0,360))
(RiWorldEnd())

or

(
RiWorldBegin(),
RiColor(1.0,1.0 ,1.0),
RiSurface('cons tant'),
RiSphere(1.0,-1.0,1.0,360),
RiWorldEnd()
)
Jul 18 '05 #8

Hilbert> I'm using CGKit in python which has a Renderman binding, so to
Hilbert> output the same RIB I'd write:

Hilbert> RiWorldBegin()
Hilbert> RiColor(1.0,1.0 ,1.0)
Hilbert> RiSurface('cons tant')
Hilbert> RiSphere(1.0,-1.0,1.0,360)
Hilbert> RiWorldEnd()

Hilbert> But I get an error, because python interprets my indentation as
Hilbert> a block in the python code.

As it should, because whitespace is significant in Python.

Hilbert> So the only way to write this is without the indentation:

Hilbert> RiWorldBegin()
Hilbert> RiColor(1.0,1.0 ,1.0)
Hilbert> RiSurface('cons tant')
Hilbert> RiSphere(1.0,-1.0,1.0,360)
Hilbert> RiWorldEnd()

Hilbert> But this is a lot harder to read.

Hilbert> Is there any way to use such "visual" indentation in python?

In this case, just use "if 1:"

RiWorldBegin()
if 1:
RiColor(1.0,1.0 ,1.0)
RiSurface('cons tant')
RiSphere(1.0,-1.0,1.0,360)
RiWorldEnd()

Skip

Jul 18 '05 #9
On Fri, 2003-08-22 at 11:10, Hilbert wrote:
Hello,

I'm using python to output RIB streams for Renderman.
The RIB stream is a bunch of statements which describes
a 3d image. The Rib standard allows for blocks which we
usually indent for better visualization for example:

WorldBegin
Color [1 1 1]
Surface "constant"
Sphere(1.0, -1.0, 1.0, 360)
WorldEnd

I'm using CGKit in python which has a Renderman binding,
so to output the same RIB I'd write:

RiWorldBegin()
RiColor(1.0,1.0 ,1.0)
RiSurface('cons tant')
RiSphere(1.0,-1.0,1.0,360)
RiWorldEnd()

But I get an error, because python interprets my indentation
as a block in the python code. So the only way to write this
is without the indentation:

RiWorldBegin()
RiColor(1.0,1.0 ,1.0)
RiSurface('cons tant')
RiSphere(1.0,-1.0,1.0,360)
RiWorldEnd()

But this is a lot harder to read.

Is there any way to use such "visual" indentation in python?


How about this? It creates a bit of unnecessary overhead (a single
tuple creation), but looks okay visually (and Emacs correctly indents
it):

RiWorldBegin()
(
RiColor(1.0,1.0 ,1.0),
RiSurface('cons tant'),
RiSphere(1.0,-1.0,1.0,360),
)
RiWorldEnd()
Regards,

--
Cliff Wells, Software Engineer
Logiplex Corporation (www.logiplex.net)
(503) 978-6726 (800) 735-0555
Jul 18 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
1260
by: Magnus Lie Hetland | last post by:
Not many members on the Atox mailing list yet, so I'll venture a request here... In Atox 0.2, I've added support for indentation tokens (somewhat like the Python indentation scheme, but a bit more relaxed). If anyone finds that sort of thing interesting, please have a look and give me your opinion -- does it seem like a useful way of dealing with this sort of thing? (It seems that lookahead is more sorely needed with indentation, to
147
7801
by: Sateesh | last post by:
Hi, I am a beginner in Python, and am wondering what is it about the indentation in Python, without which python scripts do not work properly. Why can't the indentation not so strict so as to give better freedom to the user? Is there any plausible reason behind this? Cheers! Sateesh
177
7109
by: C# Learner | last post by:
Why is C syntax so uneasy on the eye? In its day, was it _really_ designed by snobby programmers to scare away potential "n00bs"? If so, and after 50+ years of programming research, why are programming languages still being designed with C's syntax? These questions drive me insane. Every waking minute...
7
5879
by: diffuser78 | last post by:
I am a newbie to Python. I am mainly using Eric as the IDE for coding. Also, using VIM and gedit sometimes. I had this wierd problem of indentation. My code was 100% right but it wont run because indentation was not right. I checked time and again but still no success. I rewrote the code over again in VI and it ran. Can you please explain whats the trick behind the correct indentation. Thanks
9
3183
by: John Salerno | last post by:
How do you make a single string span multiple lines, but also allow yourself to indent the second (third, etc.) lines so that it lines up where you want it, without causing the newlines and tabs or spaces to be added to the string as well? Example (pretend this is all on one line): self.DTD = '<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"\n"http://www.w3.org/TR/html4/strict.dtd">\n\n'
135
7544
by: Xah Lee | last post by:
Tabs versus Spaces in Source Code Xah Lee, 2006-05-13 In coding a computer program, there's often the choices of tabs or spaces for code indentation. There is a large amount of confusion about which is better. It has become what's known as “religious war” — a heated fight over trivia. In this essay, i like to explain what is the situation behind it, and which is proper.
4
1807
by: bearophileHUGS | last post by:
This is the best praise of semantic indentation I have read so far, by Chris Okasaki: http://okasaki.blogspot.com/2008/02/in-praise-of-mandatory-indentation-for.html A quotation: I have appreciated that article, and I have personally seen how fast students learn Python basics compared to other languages, but I think that it's way more than just indentation that makes the Python language so quick to learn .
1
1690
by: Eric S. Johansson | last post by:
in trying to make programming in Python more accessible to disabled programmers (specifically mobility impaired speech recognition users), and hitting a bit of a wall. The wall (for today) is indentation. I need a method of getting the "right indentation" without having to speak a bunch of unnecessary commands. For example, depth specified by the previous line. But, frequently you need to go to a more arbitrary indentation for example...
19
2109
by: Eric S. Johansson | last post by:
Almar Klein wrote: there's nothing like self interest to drive one's initiative. :-) 14 years with speech recognition and counting. I'm so looking to my 15th anniversary of being injured next year.... another initiative is exporting the speech recognition environment to the Linux context. In a nutshell, he dictated to application on Windows, it tunnels over the network to a Linux machine, and will allow you to cut and paste to and...
0
9716
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, well explore What is ONU, What Is Router, ONU & Routers main usage, and What is the difference between ONU and Router. Lets take a closer look ! Part I. Meaning of...
0
9596
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10356
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10103
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7644
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupr who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6874
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5536
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5676
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3839
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.