Skip to main content

Hi

how can I create an empty txt-file with the python startup script?

That file has to be into the same directory, where the data in the workflow will writen to. So I will need the "DestDataset_SHAPE" as the directory and "LTYP.mif" as the filename.

Thanks very much for your support.

An example.

# Startup Python Script Example
import fme, os

# Get the destination folder path.
dir = fme.macroValuesm'DestDataset_SHAPE']

# Create the folder if it doesn't exist.
if not os.path.exists(dir):
    os.makedirs(dir)
    
# Create an empty file.
# Open a file with writing mode, and then just close it.
with open(os.path.join(dir, 'LTYP.mif'), 'w'):
    pass

Hi

Try something like this:

shape_dir = FME_MacroValuesa'DestDataset_SHAPE']
filename = shape_dir + '/LTYP.mif'
open(filename, 'w').close()

David


Thanks for this answers. I tried both, but I get allways this error message:

|ERROR |Python Exception <IndentationError>: unexpected indent (<string>, line 2)

|ERROR |Error executing string ` # Startup Python Script Example

import fme, os

# Get the destination folder path.

dir = fme.macroValues['DestDataset_SHAPE']

# Create the folder if it doesn't exist.

if not os.path.exists(dir):

os.makedirs(dir)

# Create an empty file.

# Open a file with writing mode, and then just close it.

with open(os.path.join(dir, 'LTYP.mif'), 'w'):

pass'

|ERROR |FME_BEGIN_PYTHON failed to execute provided script

What could be the problem here?


Thanks for this answers. I tried both, but I get allways this error message:

|ERROR |Python Exception <IndentationError>: unexpected indent (<string>, line 2)

|ERROR |Error executing string ` # Startup Python Script Example

import fme, os

# Get the destination folder path.

dir = fme.macroValues['DestDataset_SHAPE']

# Create the folder if it doesn't exist.

if not os.path.exists(dir):

os.makedirs(dir)

# Create an empty file.

# Open a file with writing mode, and then just close it.

with open(os.path.join(dir, 'LTYP.mif'), 'w'):

pass'

|ERROR |FME_BEGIN_PYTHON failed to execute provided script

What could be the problem here?

Identations are meaningful in Python, you will have to make sure you match the exact same indents as used by Takashi. Otherwise you will get this error.


Reply