[Solved] Write to file doesnt work “Indentation error” [duplicate]


If the rest of the code is correct, this should do:

def add_sighting(session, spawn_id, pokemon):  
    obj = Sighting(  
        pokemon_id=pokemon['id'],  
        spawn_id=spawn_id,  
        expire_timestamp=pokemon['disappear_time'],
        normalized_timestamp=normalize_timestamp(pokemon['disappear_time']),  
        lat=pokemon['lat'],  
        lon=pokemon['lng'],  
    )  
    # Check if there isn't the same entry already  
    existing = session.query(Sighting) \  
        .filter(Sighting.pokemon_id == obj.pokemon_id) \  
        .filter(Sighting.spawn_id == obj.spawn_id) \  
        .filter(Sighting.expire_timestamp > obj.expire_timestamp - 10)     \
        .filter(Sighting.expire_timestamp < obj.expire_timestamp + 10) \ 
        .filter(Sighting.lat == obj.lat) \  
        .filter(Sighting.lon == obj.lon) \  
        .first()   
    if existing:  
        return  
    session.add(obj) 

    f = open('i:\Games\Pokemon GO\pokeminer-0.2\spawn_location.csv','w')    
    f.write(pokemon_id+lon+lat+expire_timestamp)    
    f.close()

That’s because Python does not use explicit delimiters to its functions like other languages (e.g. C flavored languages, which use curly braces {}). Instead, Python uses indentation to define where functions start and where they end. def is how you start a function, and add_sighting is the name of the function. Everything after that is (probably) within the function, and therefore should be indented.

0

solved Write to file doesnt work “Indentation error” [duplicate]