473,698 Members | 2,379 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

space/tab conversion utility?

Is there any utility to convert Python sources from space-based
block indentation to tab-based?

You can use "expand" convert from tabs->spaces, but "unexpand"
isn't bright enough to do the reverse.

--
Grant Edwards grante Yow! By MEER biz doo
at SCHOIN...
visi.com
Jul 18 '05
15 3517
On 2004-07-29, Tim Peters <ti********@gma il.com> wrote:
[Grant Edwards, wants to convert spaces to tabs]
...
2) Simply converting all leading spaces to the right number of
tabs (unexpand knows how to do that) isn't correct. Only
the spaces that are block-indent spaces should be converted.

...

reindent.py is in your Python distribution, and is the state
of the art for "intelligen t" conversion of tab-infected files
to space-celebrating ones. I understand that's not the
direction you want, but it is the *code* you want to start
from. [...]


That does indeed sound like the right starting point. The
other option I can think of would be to hack up Jed's
Python-mode so that it attempts to automatically detect whether
tabs or spaces should be used.

Or I could go work on my car.

--
Grant Edwards grante Yow! BEEP-BEEP!! I'm a
at '49 STUDEBAKER!!
visi.com
Jul 18 '05 #11
[Tim Peters <ti********@gma il.com>:]
reindent.py is in your Python distribution, and is the state of the
art for "intelligen t" conversion of tab-infected files to
space-celebrating ones.


I'm carrying a question around for quite a while now and it seems to
fit into this context. The issue is "configurat ion files".

I'm not really happy with "configpars er" for some reasons and would
much more use python code itself as the natural und preferred way to
write configuration data.

The idea is to read the configuration file, which should be Python
code, and accept only statements that can't be harmful. A grammar
somehow like this (as a sketch, written before breakfast):

value := "string constant" | "num constant" | ...
seq := (value*) | [value*]
assignment := name = seq | value
.... and so on. To be elaborated.

In words: have assignments in the config file and accept only values
and structures that can do no harm. I'm not familiar with tokenizing
and python source code parsing yet.

My question:

Do you think I could accomplished this using standard Python means?
I'm thinking of the tokenize module, which I haven't used yet.

Will it be possible / easy / difficult?

Martin



Jul 18 '05 #12

- Open file in editor which uses tabs (like Scite set to use tabs)
- Ctrl-A
- Tab
- Shift-Tab
- Et voilà...

This just indents and dedents the whole program. A side-effect is that
the editor converts spaces to tabs. It also works the other way.

If your program is worrectly indented, it'll stay that way with tabs.

On 28 Jul 2004 21:49:34 GMT, Grant Edwards <gr****@visi.co m> wrote:
Is there any utility to convert Python sources from space-based
block indentation to tab-based?

You can use "expand" convert from tabs->spaces, but "unexpand"
isn't bright enough to do the reverse.


Jul 18 '05 #13
On 28 Jul 2004 21:49:34 GMT, Grant Edwards <gr****@visi.co m> wrote:
Is there any utility to convert Python sources from space-based
block indentation to tab-based?


WingIDE (commercial; http://www.wingware.com/) does the switching in both
ways at any time!
Regards,
Marco
Jul 18 '05 #14
Grant Edwards <gr****@visi.co m> writes:
So that I can submit patches to a Python application whos
devloper uses tabs. My Python editor uses spaces.


You have different options to the diff command for this:

-E --ignore-tab-expansion Ignore changes due to tab expansion.
-b --ignore-space-change Ignore changes in the amount of white space.
-w --ignore-all-space Ignore all white space.
-B --ignore-blank-lines Ignore changes whose lines are all blank.

Otherwise, a simple sed script might do it (convert 4 spaces to one
tab for example):

sed -e "s/ /\t/g/"

Catalin
Jul 18 '05 #15
On 2004-07-29, Catalin Marinas <ca************ *@arm.com> wrote:
So that I can submit patches to a Python application whos
devloper uses tabs. My Python editor uses spaces.
You have different options to the diff command for this:

-E --ignore-tab-expansion Ignore changes due to tab expansion.
-b --ignore-space-change Ignore changes in the amount of white space.
-w --ignore-all-space Ignore all white space.
-B --ignore-blank-lines Ignore changes whose lines are all blank.


But the lines of code I added will still be indented with
spaces, and the program's author uses tabs.
Otherwise, a simple sed script might do it (convert 4 spaces
to one tab for example):

sed -e "s/ /\t/g/"


Nope, that doesn't work for reasons already discussed. Even if
you restrict it to spaces at the beginning of the line (e.g.
unexpand -t4 --first-only) it still breaks things.

--
Grant Edwards grante Yow! I just remembered
at something about a TOAD!
visi.com
Jul 18 '05 #16

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

Similar topics

1
1231
by: Canneloni | last post by:
Is there a conversion utility that will take a SQL server database and port it to mySql ( or postGres sql ) ? -- W '04 <:> Open
6
2162
by: Mark Miller | last post by:
I have a scheduled job that uses different XSL templates to transform XML and save it to disk. I am having problems with the code below. The problem shows up on both my development machine (Windows XP Pro SP 1, .Net Framework 1.1) and on our production server (Windows 2K SP 4, .Net Framework 1.1). I have simplified the code and data to isolate the problem. When I use the xsl:strip-space (Line 12) declaration in conjunction with the xsl:sort...
2
2259
by: Brian Pelton | last post by:
My basic question is this: Is there a Conversion class in the .Net framework that you can pass and object to and a type to and get back an object of the given type? For example. Let's say I have a string value of "32". Is there a method that will take "32" and Type.GetType("System.Int32") and return an object of the in32 type? What I have now is a utility class that does that, but I was hoping that
5
2171
by: Konstantin Andreev | last post by:
Recently I became interested, - Are the data, bulk loaded in the table with LOAD utility, consume the same disk space as loaded with IMPORT utility? The answer turned out to be NOT ! Here is a nutshell description of the test. The testing was done at "DB2/LINUX 8.2.3". Tables for tests: F4106 has 5203 rows, 32 columns. F42199 has 1399252 rows, 245 columns.
31
3135
by: Martin Jørgensen | last post by:
Hi, I've had a introductory C++ course in the spring and haven't programmed in C++ for a couple of months now (but I have been programmed in C since january). So I decided to do my conversion utility in C++, before I forget everything. But it doesn't compile: ------------
5
7215
by: =?Utf-8?B?U2hhaWxlbiBTdWt1bA==?= | last post by:
I have some code that was written in managed C++ using VS 2005. I want to convert that code into C#. Is there a tool available to do this? Thanks in advance. -- Shailen Sukul Architect (BSc MCTS, MCSD.Net MCSD MCAD) Ashlen Consulting Service P/L
10
2083
by: Phil Stanton | last post by:
I have a table of SpaceAreas eg Food Store, Garden Shed etc with the first and last bin for each Space Area defined. eg Food Store First Space 1, last space 26 and Gargen Shed First space 1, last Space 50. SpaceAreas Table is SpaceAreaID Auto SpaceAreaDesc Text FirstSpace Integer LastSpace Integer I have a secont table of the Equipment Stored in each space
0
1870
by: vikasthukral17 | last post by:
Hello Friends i want to convert xml shown under into excel file,xml is as <?xml version="1.0" standalone="yes"?> <?xml-stylesheet type="text/xsl" href="AggrPositions.xsl"?> <DataOut> <NoName> <AggregatedPosition> <PositionReference>549</PositionReference>
1
7123
by: HxRLxY | last post by:
I have a program that shows a thumbnail of an image. If the user clicks on the thumbnail a new JFrame is opened that shows the full size image. If the image is larger than the screen, it gets scaled to the the size of the screen. Functionally, the program works well. However, when testing I found that after clicking the thumbnails of several images (and subsequently closing their viewing frames), I get an java.lang.OutOfMemoryError: Java...
0
9029
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...
1
8897
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
8862
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
7729
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
6521
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
4370
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
4619
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3050
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
2331
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.