Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4610558
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T01:08:54+00:00 2026-05-22T01:08:54+00:00

I am trying to make some edits to a docx file… making a number

  • 0

I am trying to make some edits to a docx file… making a number into letter (i.e. if the variable is equal to 01 = ‘one’, equal to 02 = ‘two’, and so on, but in Spanish). The problem is that the variable f_dia_nom doesn’t work … it doesn’t even print anything… am I doing something wrong?? or am I missing something??

#!/usr/bin/env python2.6

from Tkinter import *
from docx import *
import tkMessageBox

root = Tk()

nombre = ""
exp_no = ""
ubic = ""
munic = ""
prov = ""
f_dia = ""
f_dia2 = ""
f_dia_nom = ""

def nombre_dia():
         if f_dia2 == 1 or f_dia2 == 01:        
             f_dia_nom = "Un"
         elif f_dia2 == 2 or f_dia2 == 02:               
             f_dia_nom  =  "Dos"
         elif f_dia2 == 3 or f_dia2 == 03:        
             f_dia_nom = "Tres"
         elif f_dia2 == 4 or f_dia2 == 04:               
             f_dia_nom = "Cuatro"
         elif f_dia2 == 5 or f_dia2 == 05:               
             f_dia_nom = "Cinco"
         elif f_dia2 == 6 or f_dia2 == 06:        
             f_dia_nom = "Seis"
         elif f_dia2 == 7 or f_dia2 == 07:               
             f_dia_nom = "Siete"             
         else:
             f_dia_nom = "Error"

# Hacer el docx      
def makedocx():
         if __name__ == '__main__':        
             # Default set of relationshipships - these are the minimum components of a document
             relationships = relationshiplist()

             # estructura del documento
             document = opendocx('test.docx')
             docbody = document.xpath('/w:document/w:body',namespaces=nsprefixes)[0]

             # Buscar y reemplazar
             print 'Replacing ...',
             docbody = replace(docbody,'V_EXP',en1.get())            
             docbody = replace(docbody,'V_NOMBRE',en0.get()) 
             docbody = replace(docbody,'V_OPERACION',op.get())           
             docbody = replace(docbody,'V_UBIC',en3.get())
             docbody = replace(docbody,'V_MUNI',en4.get())
             docbody = replace(docbody,'V_PROV',en5.get())
             docbody = replace(docbody,'V_F_DIA',en6.get())
             docbody = replace(docbody,'V_F_MES',mes.get())          
             docbody = replace(docbody,'V_F_SEM',sem.get())
             docbody = replace(docbody,'V_NUM_DIA',en7.get())            
             nombre_dia()
             docbody = replace(docbody,'V_NOM_DIA',f_dia_nom)            
             print 'f_dia_nom'
             print 'done.'
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T01:08:55+00:00Added an answer on May 22, 2026 at 1:08 am

    Look up ‘global scoping’ rules for python. In general, try to avoid global variables as much as possible(if only to avoid errors like these)

    in nombre_dia():

    f_dia_nom = "Un" 
    

    or any other assignment for that matter has the python compiler create that number LOCAL to the nombre_dia function.

    modify your function to declare f_dia_nom as a global:

    def nombra_dia():
       global f_dia_nom
    
       ...
    

    It will have nombre_dia SEE the f_dia_nom as the global

    References

    Learning Python 4th edition pg 408

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm currently trying to read in an XML file, make some minor changes (alter
I'm trying to make an image editor with canvas, but I ran into some
I've been trying to make a basic XOR header file for use in some
I'm trying to make some kind of strange polymorphism on C++: I have two
I'm trying to make some types in Django that map to standard Django types.
I'm trying to make some simple XML with Java and org.w3c.dom, but I got
I'm trying to make some text bold using HTML, but I'm struggling to get
I'm trying to make some social share buttons at my site, but the urls
I'm using TCPDF in CakePHP and trying to make some background (grey) for few
I am working on a database schema, and am trying to make some decisions

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.