Jump to content
COMBATSIM Forum
Sign in to follow this  
mikew

python format check

Recommended Posts

if cup=='DD':

print 'WoW!'


if cup=='DD':

print 'WoW!'

That actually nearly worked, but in general, if I try and post code with tabs or blank lines, most formatting is lost. :(

How can I post , so that I see exactly what I started off with in Notepad or Notepad++ ??

EDIT:

That's changed! The tabs that were there disappeared after editing the post. :angry:

Share this post


Link to post
Share on other sites

Mike,

I'll look into this tomorrow. If I can, I'll try to find something that lets you post code with syntax highlighting :)

Share this post


Link to post
Share on other sites

Thanks!

The important thing is that my whitespace is respected, specially inside 'CODE' tags.

From what I've seen, the whitespace is 'eroded' away somehow. This is disastrous for Python, and annoying when trying to format a table.

Share this post


Link to post
Share on other sites

I haven't changed anything yet, I just want to do a couple of tests.

Okay, let's first try a sample Python script:



number1 = raw_input( "Please enter the first integer: " )
number1 = int(number1)

number2 = raw_input( "Please enter the second integer:" )
number2 = int(number2)

if number1 == number2:
print "%d is equal to %d" % (number1, number2)

if number1 != number2:
print "%d is not equal to %d" % (number1, number2)

if number1 < number2:
print "%d is less than %d" % (number1, number2)

if number1 > number2:
print "%d is greater than %d" % (number1, number2)

if number1 <= number2:
print "%d is less than or equal to %d" % (number1, number2)

if number1 >= number2:
print "%d is greater than or equal to %d" % ( number1, number2 )

dummy=raw_input()
[/code] Hmmm ... that seems to be working just fine. All the whitespace is preserved. Mike: I'm sure you know this, after all, you are using Python, so you must be using a plain text editor, but are your doing anything that might be interfering with the code in the forum editor? I'm not doing anything special; in fact, I'm copying the code in my plain text editor, then using the regular full-on rich text editor here in the forum. I suppose you could use the toggle in the forum editor to switch to raw text mode to see if that helps. Here's another Python script, just to check:
[code]

from datetime import date

def daysBetween(firstYear,firstMonth,firstDay,secondYear,secondMonth,secondDay):
if int(firstYear) > int(secondYear):
y1 = int(firstYear)
m1 = int(firstMonth)
d1 = int(firstDay)
y2 = int(secondYear)
m2 = int(secondMonth)
d2 = int(secondDay)
else:
y1 = int(secondYear)
m1 = int(secondMonth)
d1 = int(secondDay)
y2 = int(firstYear)
m2 = int(firstMonth)
d2 = int(firstDay)

days = date(y1, m1, d1) - date(y2, m2, d2)
return days

Share this post


Link to post
Share on other sites

In the first post, I created text with Notepad++ which is set up to replace a tab with 4 spaces.

There are two lines with a 'tab' starting the second line.

I then copied and pasted it into the forum, with and without 'code' tags.

The formatting was fine to start, but editing the post seemed to mess it up.

Yesterday, I tried the toggle button, but it seemed to make things worse if anything...

EDIT:

this is done in notepad, lines 2 and 3 use tabs, 4 & 5 use spaces:


some text

one tab

  2 tabs

    after 4 spaces

	    after 8 spaces

Share this post


Link to post
Share on other sites

Lemme try your example:


some text
one tab
2 tabs
after 4 spaces
after 8 spaces
[/code]

Looks like the forum is doubling the number of spaces in the code. I'll have to look into this.

[EDIT: oh yeah, it's totally borking the spacing after editing the post, too!]

Share this post


Link to post
Share on other sites

Okay, let's try this.

I created a Pastebin tag so you can post your code over at Pastebin.com, then wrap the embed url in the new tags I created.

So, if you go to Pastebin.com and post your code, you can click the "Embed" link and it gives you two options: Javascript embedding, or an IFrame. I made the new tag compatible with the Javascript IFrame version, so here's what you'd be presented with for an embed code at Pastebin:


<iframe src="http://pastebin.com/embed_iframe.php?i=bKG4wF6z" style="border:none;width:100%"></iframe>
[/code] Take just the id code from the URL, the bit after i=. In the URL above, that would be this code:
[code]
bKG4wF6z
And put that into our new forum tags like so:

[pastebin]bKG4wF6z[/pastebin]
[/code]

Which should produce this result:

Working now :)

Note: Be sure to re-read how-to steps above because I changed the instructions somewhat.

Share this post


Link to post
Share on other sites

Bump.

Have to do this because I deleted a post in here and for some reason the site is showing last post by "Guest" so I wanted to get rid of that.

Share this post


Link to post
Share on other sites

Mike,

Yes, you post it at Pastebin in your own account, but you can decide to make the code "public" or "unlisted". Just choose unlisted if you only want the guys in your private forum to see it.

Share this post


Link to post
Share on other sites

Thanks for looking into it, but I'm not signing up for yet another online service just for this.

Is it really, really impossible to post some 8-bit ascii code without it being attacked by your killer tags?

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×