473,789 Members | 2,479 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

DOS, UNIX and tabs

Ben
Hi,

I have a python script on a unix system that runs fine. I have a python
script on a windows system that runs fine. Both use tabs to indent
sections of the code. I now want to run them on the same system,
actually in the same script by combining bits and pieces. But whatever
I try my windows tabs get converted to spaces when I transfer it to the
unix system and the interpreter complains that the indentation style is
not consistent throughout the file. Short of going through 350 lines of
code and manually replacing spaces with tabs what an I do? I'm thinking
there surely must be a simple solution I have missed here!

Cheers,

Ben

Dec 27 '06 #1
35 2725
Ben
I've found the unexpand command, which seems to do the trick. However,
it outputs to standard output, and I haven't worked out yet how to
capture that output to a file...

Ben

Ben wrote:
Hi,

I have a python script on a unix system that runs fine. I have a python
script on a windows system that runs fine. Both use tabs to indent
sections of the code. I now want to run them on the same system,
actually in the same script by combining bits and pieces. But whatever
I try my windows tabs get converted to spaces when I transfer it to the
unix system and the interpreter complains that the indentation style is
not consistent throughout the file. Short of going through 350 lines of
code and manually replacing spaces with tabs what an I do? I'm thinking
there surely must be a simple solution I have missed here!

Cheers,

Ben
Dec 27 '06 #2
On 2006-12-27, Ben <Be************ *@gmail.comwrot e:
I've found the unexpand command, which seems to do the trick. However,
it outputs to standard output, and I haven't worked out yet how to
capture that output to a file...
unexpand <file1 >file2

--
Grant Edwards grante Yow! Hey, LOOK!! A pair of
at SIZE 9 CAPRI PANTS!! They
visi.com probably belong to SAMMY
DAVIS, JR.!!
Dec 27 '06 #3
Ben
Great - that worked.Thanks!
Is that a general method in linux you can always use to redirect
standard output to a file?

Cheers,

Ben
Grant Edwards wrote:
On 2006-12-27, Ben <Be************ *@gmail.comwrot e:
I've found the unexpand command, which seems to do the trick. However,
it outputs to standard output, and I haven't worked out yet how to
capture that output to a file...

unexpand <file1 >file2

--
Grant Edwards grante Yow! Hey, LOOK!! A pair of
at SIZE 9 CAPRI PANTS!! They
visi.com probably belong to SAMMY
DAVIS, JR.!!
Dec 27 '06 #4
On 2006-12-27, Ben <Be************ *@gmail.comwrot e:
>>I've found the unexpand command, which seems to do the trick. However,
it outputs to standard output, and I haven't worked out yet how to
capture that output to a file...

unexpand <file1 >file2
Great - that worked.Thanks!

Is that a general method in linux you can always use to redirect
standard output to a file?
Yup. The "<" operator redirects stdin, the ">" operator
redirects stdout. "2>" redirects stderr.

--
Grant Edwards grante Yow! Let's go to CHURCH!
at
visi.com
Dec 27 '06 #5
Ben <Be************ *@gmail.comtype d
I have a python script on a windows system that runs fine. Both use
tabs to indent sections of the code.
Just a tip for you: In python you never use tabs for indentation. The
python style guide [1] recommends four spaces per indentation level.

[1] http://www.python.org/dev/peps/pep-0008/

--
Freedom is always the freedom of dissenters.
(Rosa Luxemburg)
Dec 27 '06 #6
"Sebastian 'lunar' Wiesner" <ba***********@ gmx.netwrites:
Just a tip for you: In python you never use tabs for indentation.
For some value of "you".
The python style guide [1] recommends four spaces per indentation
level.

[1] http://www.python.org/dev/peps/pep-0008/
It's not quite absolute on the topic:

For new projects, spaces-only are strongly recommended over tabs.

--
\ "I filled my humidifier with wax. Now my room is all shiny." |
`\ -- Steven Wright |
_o__) |
Ben Finney

Dec 27 '06 #7
At Wednesday 27/12/2006 20:09, Ben Finney wrote:
The python style guide [1] recommends four spaces per indentation
level.

[1] http://www.python.org/dev/peps/pep-0008/

It's not quite absolute on the topic:

For new projects, spaces-only are strongly recommended over tabs.
Of course you can do it anyway you like, but you should have a
*strong* reason for not following a *strong* recommendation.
(Just a note, you can use untabify.py (inside the Tools dir) to
convert tabs to spaces, instead of unexpand)
--
Gabriel Genellina
Softlab SRL


_______________ _______________ _______________ _____
Preguntá. Respondé. Descubrí.
Todo lo que querías saber, y lo que ni imaginabas,
está en Yahoo! Respuestas (Beta).
¡Probalo ya!
http://www.yahoo.com.ar/respuestas

Dec 28 '06 #8

"Ben Finney" <bi************ ****@benfinney. id.auwrote in message
news:ma******** *************** *************** *@python.org...
"Sebastian 'lunar' Wiesner" <ba***********@ gmx.netwrites:
Just a tip for you: In python you never use tabs for indentation.

For some value of "you".
The python style guide [1] recommends four spaces per indentation
level.

[1] http://www.python.org/dev/peps/pep-0008/

It's not quite absolute on the topic:

For new projects, spaces-only are strongly recommended over tabs.
Even if were, read the Introduction. This is a coding standard intended
to apply to code which is going to checked in as part of the core python
build, not all Python! It's probably a pretty good standard to be following
in general, but come on... If Guido really wanted this enforced across the
board he could simply call anything that doesn't meet this standard to the
letter a SyntaxError and just stop there. For example, the standard states:

- Imports should usually be on separate lines, e.g.:

Yes: import os
import sys

No: import sys, os
>>import sys, os
Traceback (most recent call last):
File "<stdin>", line 1, in ?
ImportError: Sorry, only one module per import line!
I'm sure that's not Guido's intention. ;)

-ej
Dec 28 '06 #9
On Wed, 27 Dec 2006 20:15:33 +0100, Sebastian 'lunar' Wiesner wrote:
Ben <Be************ *@gmail.comtype d
>I have a python script on a windows system that runs fine. Both use
tabs to indent sections of the code.

Just a tip for you: In python you never use tabs for indentation. The
python style guide [1] recommends four spaces per indentation level.

[1] http://www.python.org/dev/peps/pep-0008/
[obligatory pot-shot in the never-ending spaces versus tabs war]

In Python, I frequently use tabs for indentation, and I never have any
trouble *except* when posting code to Usenet, where other people's news
readers can't cope with tabs.

But I think we all agree that mixing tabs and spaces is A Very Bad Thing.

--
Steven D'Aprano

Dec 28 '06 #10

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

Similar topics

7
4063
by: Kayle | last post by:
For preservation of indentation when moving the C source file from Windows to Linux machine, what is the advice to format the code. Should the code formatted using spaces instead of tabs? When opened using nedit in Linux, the indentation was not preserved, or should we limit the length of each line ? Any advice on this ? Thanks
135
7531
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.
1
295
by: Ben | last post by:
Hi, I have a python script on a unix system that runs fine. I have a python script on a windows system that runs fine. Both use tabs to indent sections of the code. I now want to run them on the same system, actually in the same script by combining bits and pieces. But whatever I try my windows tabs get converted to spaces when I transfer it to the unix system and the interpreter complains that the indentation style is not consistant...
7
3759
by: Phil Reynolds | last post by:
I'm using a tab control in Access 2000, and the user requested to have buttons in the form header, instead of the built-in tabs (so that when they scroll down, they can still switch tabs). Now, this works fine. However, when I'm in Design View, I can't access the tabs without changing the tab control's Style back to Tabs. But I want to be able to place controls in that space at the top where the tabs used to be. But if I need to turn the...
0
9502
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
10383
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10128
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9971
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...
0
9000
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7521
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
5541
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4080
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3678
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.