I'm running this code but I get an indent error. What seems to be the problem? I ran it so many times. When I run the code through IDLE, I get this box that says:
Syntax Error: There's and error in your program: expected an indented
block
Code:
import arcpy
from arcpy import env
import math
folder_path = r"J:\sanda"
# Define workspace as your folder path
env.workspace = folder_path
# Allow overwriting output files
arcpy.env.overwriteOutput = True
#parameters as text
input_lake = arcpy.GetParameterAsText(0)
input_cities = arcpy.GetParameterAsText(1)
output_lake = arcpy.GetParameterAsText(2)
city= "CITY_NAME"
cntry= "CITY_CNTRY"
admin= "ADMIN_NAME"
pop_city= "Population"
dist_km= "Distance"
x_coord= "X_CORD"
y_coord= "Y_CORD"
#copy lakes shapefile
arcpy.CopyFeatures_management(input_lake, output_lake)
#Add fields (city_name, x coord, y coord, etc)
arcpy.AddField_management(output_lake, city, "TEXT")
arcpy.AddField_management(output_lake, cntry , "TEXT")
arcpy.AddField_management(output_lake, admin, "TEXT")
arcpy.AddField_management(output_lake, pop_city, "DOUBLE")
arcpy.AddField_management(output_lake, dist_km, "DOUBLE")
arcpy.AddField_management(output_lake, x_coord, "DOUBLE")
arcpy.AddField_management(output_lake, y_coord, "DOUBLE")
#create empty lists
citylist_city_name = []
citylist_X = []
citylist_Y = []
city_name = []
city_cntry = []
admin_name = []
dist_km= []
pop= []
#populate these lists with values
city_cursor= arcpy.SearchCursor(input_cities)
for city in city_cursor:
geom = city.Shape
citylist_X.append(geom.firstPoint.X)
citylist_Y.append(geom.firstPoint.Y)
citylist_city_name.append(city.CITY_NAME)
city_cntry.append(city.CNTRY_NAME)
admin_name.append(city.ADMIN_NAME)
pop.append(city.Population)
#get the number of cities
city_length = len(citylist_X)
#read lake geometries
lake_cursor = arcpy.UpdateCursor(output_lake)
#loop through each lake
for lake in lake_cursor:
lake_geom = lake.Shape
#initiate lake distances
city_dist_list = []
#loop through each city
for cityID in range(0, city_length - 1):
#get x and y for the current city
cityX=citylist_X[cityID]
cityY=citylist_Y[cityID]
#get x and y for the current lake
lakeX = lake_geom.centroid.X
lakeY = lake_geom.centroid.Y
#calculate the distance
dist = math.sqrt((cityX-lakeX)**2 +(cityY-lakeY)**2
city_dist_list.append(dist)
closest = min(city_dist_list)
closestID = city_dist_list.index(closest)
#set values into the new lake feature
lake.CITY_NAME = citylist_city_name[closestID]
lake.X_CORD = citylist_X [closestID]
lake.Y_CORD = citylist_Y [closestID]
lake.Distance = closest*(0.001)
lake.ADMIN_NAME = admin_name [closestID]
lake.Population = pop [closestID]
lake.city_cntry = city_cntry [closestID]
lake_cursor.updateRow(lake)
#kill the cursors
del city_cursor, lake_cursor, lake, city, cityID, geom, lake_geom
print "Done"
The for-loop in your code is not indented properly, it must be like this :
for cityID in range(0, city_length - 1):
#get x and y for the current city
cityX=citylist_X[cityID]
cityY=citylist_Y[cityID]
#get x and y for the current lake
lakeX = lake_geom.centroid.X
lakeY = lake_geom.centroid.Y
#calculate the distance
dist = math.sqrt((cityX-lakeX)**2 +(cityY-lakeY)**2)
city_dist_list.append(dist)
closest = min(city_dist_list)
closestID = city_dist_list.index(closest)
#set values into the new lake feature
lake.CITY_NAME = citylist_city_name[closestID]
lake.X_CORD = citylist_X [closestID]
lake.Y_CORD = citylist_Y [closestID]
lake.Distance = closest*(0.001)
lake.ADMIN_NAME = admin_name [closestID]
lake.Population = pop [closestID]
lake.city_cntry = city_cntry [closestID]
lake_cursor.updateRow(lake)
Secondly you were missing a closing ) on this line:
dist = math.sqrt((cityX-lakeX)**2 +(cityY-lakeY)**2)
Related
When I use splitter_freqy.py to split my .dat filem I meet the following problem.
line 5 name=str(sys.argv[position+1])
indexerror list index out of range
I use ubuntu and the command is
python3.6 splitter_freq.py abc.dat
This is the splitter_freq.py
import sys
arguments = len(sys.argv) - 1
position = 1
name = str(sys.argv[position+1])
while (arguments > position): # changed >= to > to avoid error
bench_freq_names = []
path0 = "./%s/"%name+sys.argv[position]
position = position+1
print("the input file is ",path0)
c_0 = open(path0,'r')
header=c_0.readline()
l_0 = c_0.readline()
w_0 = l_0.split()
bench_name = w_0[1]
freq_value = w_0[3]
path_out = path0.split("/")
path_out = path_out[-1].split(".")
print("the benchmark name is ",bench_name)
print("the freq value is ",freq_value)
bench_freq_names.append([bench_name,freq_value])
output_file = "./%s/"%name+path_out[0]+"_"+bench_name+"_"+freq_value+".txt"
m = open(output_file,'a')
print(header.rstrip('\n'),file=m)
print(l_0.rstrip('\n'),file=m)
for l_0 in c_0: #read lines one by one
w_0 = l_0.split()
if (w_0[1] == bench_name and w_0[3] == freq_value):
print(l_0.rstrip('\n'),file=m)
else: #new_bench_name or new freq_value
m.close() #close file
bench_name = w_0[1] #update bench
freq_value = w_0[3] #update freq
print("the benchmark name is ",bench_name)
print("the freq value is ",freq_value)
output_file = "./%s/"%name+path_out[0]+"_"+bench_name+"_"+freq_value+".txt"
m = open(output_file,'a')
if [bench_name,freq_value] not in bench_freq_names:
bench_freq_names.append([bench_name,freq_value])
print(header.rstrip('\n'),file=m)
print(l_0.rstrip('\n'),file=m)
c_0.close()
m.close()
I can find one other place where this problem is specifically addressed, but it seems to be even more personal in nature and the other thread provided no help. This is the error:
# Error: Maya command error
# Traceback (most recent call last):
# File "<maya console>", line 1, in <module>
# File "<maya console>", line 26, in createJoints
# RuntimeError: Maya command error #
And here is the code, to create a chain of joints along a premade curve:
import maya.cmds as mc
##UI##
jointCurve = mc.window(title = "Create Joint Chain") #window title#
mc.rowColumnLayout(nc = 2) #divides window into two columns#
mc.text(l = "Number of Joints") #dialog prompt#
jntAmount = mc.intField (v = 5, min = 2) #default value of 5, minimum value of 2 joints#
mc.button(l = "Create", w = 150, c = "createJoints()") #confirms entry#
mc.button(l = "Cancel", w = 150, c = "mc.deleteUI(jointCurve)") #closes window, deletes UI#
mc.showWindow() #now that all parameters are defined, the window is opened#
##Method##
def createJoints():
#Gathering Information#
selCurve = mc.ls(sl = True) [0]
jointAmount = mc.intField(jntAmount, q = True, v = True)
prevJnt = ""
rootJnt = ""
for i in range(0, jointAmount): #for each increment from 0 to the amount defined in the field,#
mc.select(cl = True) #clear the selection,#
newJnt = mc.joint() #create a joint,#
motionPath = mc.pathAnimation(newJnt, c = selCurve, fractionMode = True) #affix to curve using a motion path,#
mc.cutKey(motionPath + ".u", time = ()) #remove animation keys from joint's U value (position on curve),#
mc.setAttr(motionPath + ".u", i * (1.0/(jointAmount - 1))) #distribute joints evenly along curve#
#delete motion path#
mc.delete(newJnt + ".tx", icn = True)#deletes x translate value's input connections#
mc.delete(newJnt + ".ty", icn = True)#deletes y translate value's input connections#
mc.delete(newJnt + ".tz", icn = True)#deletes z translate value's input connections#
mc.delete(motionPath) #deletes motion path itself#
if i == 0:
prevJnt = newJnt
rootJnt = newJnt
continue #skips next instructions for root joint since it has no parent#
mc.parent(newJnt, prevJnt) #parents current joint to previous joint#
prevJnt = newJnt #sets status of "previous" joint to current joint#
mc.joint(rootJnt, e = True, oj = "xyz", sao = "yup", ch = True, zso = True) #orients joints along chain#
mc.deleteUI(jointCurve) #closes prompt window#
Whenever I run the code in a new file, it works perfectly, no issues.
But I have another file that, when I run this code, it throws the above error.
So it looks like it's having a problem somewhere with importing Maya commands?
as well as with this line, in particular:
mc.cutKey(motionPath + ".u", time = ())
For some reason, this error is thrown even when I start a new file, and import the other file into the scene.
I have absolutely no idea where to start looking..
The issue is your ui which is prior to the creation of your command
import maya.cmds as mc
from functools import partial
##Method##
def createJoints(*args):
#Gathering Information#
selCurve = mc.ls(sl = True) [0]
jointAmount = mc.intField(jntAmount, q = True, v = True)
prevJnt = ""
rootJnt = ""
for i in range(0, jointAmount): #for each increment from 0 to the amount defined in the field,#
mc.select(cl = True) #clear the selection,#
newJnt = mc.joint() #create a joint,#
motionPath = mc.pathAnimation(newJnt, c = selCurve, fractionMode = True) #affix to curve using a motion path,#
mc.cutKey(motionPath + ".u", time = ()) #remove animation keys from joint's U value (position on curve),#
mc.setAttr(motionPath + ".u", i * (1.0/(jointAmount - 1))) #distribute joints evenly along curve#
#delete motion path#
mc.delete(newJnt + ".tx", icn = True)#deletes x translate value's input connections#
mc.delete(newJnt + ".ty", icn = True)#deletes y translate value's input connections#
mc.delete(newJnt + ".tz", icn = True)#deletes z translate value's input connections#
mc.delete(motionPath) #deletes motion path itself#
if i == 0:
prevJnt = newJnt
rootJnt = newJnt
continue #skips next instructions for root joint since it has no parent#
mc.parent(newJnt, prevJnt) #parents current joint to previous joint#
prevJnt = newJnt #sets status of "previous" joint to current joint#
mc.joint(rootJnt, e = True, oj = "xyz", sao = "yup", ch = True, zso = True) #orients joints along chain#
mc.deleteUI(jointCurve) #closes prompt window#
def cancelUI(jointCurve, *args):
mc.deleteUI(jointCurve)
##UI##
jointCurve = mc.window(title = "Create Joint Chain") #window title#
mc.rowColumnLayout(nc = 2) #divides window into two columns#
mc.text(l = "Number of Joints") #dialog prompt#
jntAmount = mc.intField (v = 5, min = 2) #default value of 5, minimum value of 2 joints#
mc.button(l = "Create", w = 150, c = createJoints) #confirms entry#
mc.button(l = "Cancel", w = 150, c = partial(cancelUI, jointCurve)) #closes window, deletes UI#
mc.showWindow() #now that all parameters are defined, the window is opened#
I am trying to extract audio features from Spotify using track URIs. I have a list of 500k and would like to extract audio features for all. I have a workable code below and can extract features of 80 songs. I need some help in modifying the code below to extract 80 at a time so I don't run afoul of the Spotify limit. An example of the list is below
['spotify:track:2d7LPtieXdIYzf7yHPooWd',
'spotify:track:0y4TKcc7p2H6P0GJlt01EI',
'spotify:track:6q4c1vPRZREh7nw3wG7Ixz',
'spotify:track:54KFQB6N4pn926IUUYZGzK',
'spotify:track:0NeJjNlprGfZpeX2LQuN6c']
client_id = 'xxx'
client_secret = 'xxx'
client_credentials_manager = SpotifyClientCredentials(client_id=client_id, client_secret=client_secret)
sp = spotipy.Spotify(client_credentials_manager=client_credentials_manager)
def get_audio_features(saved_uris):
artist = []
track = []
danceability = []
energy = []
key = []
loudness = []
mode = []
speechiness = []
acousticness = []
instrumentalness = []
liveness = []
valence = []
tempo = []
duration_ms = []
for uri in saved_uris:
x = sp.audio_features(uri)
y = sp.track(uri)
for audio_features in x:
danceability.append(audio_features['danceability'])
energy.append(audio_features['energy'])
key.append(audio_features['key'])
loudness.append(audio_features['loudness'])
mode.append(audio_features['mode'])
speechiness.append(audio_features['speechiness'])
acousticness.append(audio_features['acousticness'])
instrumentalness.append(audio_features['instrumentalness'])
liveness.append(audio_features['liveness'])
valence.append(audio_features['valence'])
tempo.append(audio_features['tempo'])
duration_ms.append(audio_features['duration_ms'])
artist.append(y['album']['artists'][0]['name'])
track.append(y['name'])
df = pd.DataFrame()
df['artist'] = artist
df['track'] = track
df['danceability'] = danceability
df['energy'] = energy
df['key'] = key
df['loudness'] = loudness
df['mode'] = mode
df['speechiness'] = speechiness
df['acousticness'] = acousticness
df['instrumentalness'] = instrumentalness
df['liveness'] = liveness
df['valence'] = valence
df['tempo'] = tempo
df['duration_ms'] = duration_ms
df.to_csv('data/xxx.csv')
return df
My output is a dataframe and it looks like this and I have cut some columns for readibility:
artist track danceability energy key loudness
Sleeping At Last Chasing Cars 0.467 0.157 11
This code will return you dataframe that you require.
import spotipy
import time
from spotipy.oauth2 import SpotifyClientCredentials #To access authorised Spotify data4
import pandas as pd
client_id = 'paste client_id here'
client_secret = 'paste client_secret here'
client_credentials_manager = SpotifyClientCredentials(client_id=client_id, client_secret=client_secret)
sp = spotipy.Spotify(client_credentials_manager=client_credentials_manager)
sp.trace=False
#your uri list goes here
s_list = ['spotify:track:2d7LPtieXdIYzf7yHPooWd','spotify:track:0y4TKcc7p2H6P0GJlt01EI','spotify:track:6q4c1vPRZREh7nw3wG7Ixz','spotify:track:54KFQB6N4pn926IUUYZGzK','spotify:track:0NeJjNlprGfZpeX2LQuN6c']
#put uri to dataframe
df = pd.DataFrame(s_list)
df.columns = ['URI']
df['energy'] = ''*df.shape[0]
df['loudness'] = ''*df.shape[0]
df['speechiness'] = ''*df.shape[0]
df['valence'] = ''*df.shape[0]
df['liveness'] = ''*df.shape[0]
df['tempo'] = ''*df.shape[0]
df['danceability'] = ''*df.shape[0]
for i in range(0,df.shape[0]):
time.sleep(random.uniform(3, 6))
URI = df.URI[i]
features = sp.audio_features(URI)
df.loc[i,'energy'] = features[0]['energy']
df.loc[i,'speechiness'] = features[0]['speechiness']
df.loc[i,'liveness'] = features[0]['liveness']
df.loc[i,'loudness'] = features[0]['loudness']
df.loc[i,'danceability'] = features[0]['danceability']
df.loc[i,'tempo'] = features[0]['tempo']
df.loc[i,'valence'] = features[0]['valence']
uri=0
Output:
Hope, this solves your problem.
everyone.
I have some problems with calculating gcskews in python.
My 2 major inputs are fasta file and bed file.
Bed file has columns of gn(0), gene_type(1), gene name(2), chromosome(3), strand(4), num(5), start(6).(These numbers are index numbers in python.) Then I am trying to use some functions which can calculate gcskews of sense and antisense strand from the start site of each gene. The window is 100bp and these are the functions.
import re
import sys
import os
# opening bed file
content= []
with open("gene_info.full.tsv") as new :
for line in new :
content.append(line.strip().split())
content = content[1:]
def fasta2dict(fil):
dic = {}
scaf = ''
seq = []
for line in open(fil):
if line.startswith(">") and scaf == '':
scaf = line.split(' ')[0].lstrip(">").replace("\n", "")
elif line.startswith(">") and scaf != '':
dic[scaf] = ''.join(seq)
scaf = line.split(' ')[0].lstrip(">").replace("\n", "")
seq = []
else:
seq.append(line.rstrip())
dic[scaf] = ''.join(seq)
return dic
dic_file = fasta2dict("full.fa")
# functions for gc skew
def GC_skew_up(strand, loc, seq, window = 100) : # need -1 for index
values_up = []
loc = loc - 1
if strand == "+" :
sp_up = seq[loc - window : loc]
g_up = sp_up.count('G') + sp_up.count('g')
c_up = sp_up.count('C') + sp_up.count('c')
try :
skew_up = (g_up - c_up) / float(g_up + c_up)
except ZeroDivisionError:
skew_up = 0.0
values_up.append(skew_up)
elif strand == "-" :
sp_up = seq[loc : loc + window]
g_up = sp_up.count('G') + sp_up.count('g')
c_up = sp_up.count('C') + sp_up.count('c')
try :
skew_up = (c_up - g_up) / float(g_up + c_up)
except ZeroDivisionError:
skew_up = 0.0
values_up.append(skew_up)
return values_up
def GC_skew_dw(strand, loc, seq, window = 100) :
values_dw = []
loc = loc - 1
if strand == "+" :
sp_dw = seq[loc : loc + window]
g_dw = sp_dw.count('G') + sp_dw.count('g')
c_dw = sp_dw.count('C') + sp_dw.count('c')
try :
skew_dw = (g_dw - c_dw) / float(g_dw + c_dw)
except ZeroDivisionError:
skew_dw = 0.0
values_dw.append(skew_dw)
elif strand == "-" :
sp_dw = seq[loc - window : loc]
g_dw = sp_dw.count('G') + sp_dw.count('g')
c_dw = sp_dw.count('C') + sp_dw.count('c')
try :
skew_dw = (c_dw - g_dw) / float(g_dw + c_dw)
except ZeroDivisionError:
skew_dw = 0.0
values_dw.append(skew_dw)
return values_dw
As I said, I want to calculate the gcskews for 100bp of strands from the start site of genes.
Therefore, I made codes that get the chromosome name from the bed file and get the sequence data from the Fasta file.
Then according to gene name and strand information, I expected that codes will find the correct start site and gcskew for 100bp window will be calculated.
However, when I run this code, gcskew of - strand is wrong but + strand is correct. (I got correct gcskew data and I used it.)
Gcskews are different from the correct data, but I don't know what is the problem.
Could anyone tell me what is the problem of this code?
Thanks in advance!
window = 100
gname = []
up = []
dw = []
for match in content :
seq_chr = dic_file[str(match[3])]
if match[4] == "+" :
strand = match[4]
new = int(match[6])
sen_up = GC_skew_up(strand, new, seq_chr, window = 100)
sen_dw = GC_skew_dw(strand, new, seq_chr, window = 100)
gname.append(match[2])
up.append(str(sen_up[0]))
dw.append(str(sen_dw[0]))
if match[4] == "-" :
strand = match[4]
new = int(match[6])
an_up = GC_skew_up(strand, new, seq_chr, window = 100)
an_dw = GC_skew_dw(strand, new, seq_chr, window = 100)
gname.append(match[2])
up.append(str(an_up[0]))
dw.append(str(an_dw[0]))
tot = zip(gname, up, dw)
I am creating a Word document from data using python-docx. I can create all the rows and cells with no problem but, in some cases, when the current record from the database has some content in field comment, I need to add a new line to display a long content.
I tried by appending a paragraph, but the result is that the comment is appended after the table, and I need it to be added bellow the current table row.
I think the solution is to append a table row with all cells merged, but I can't find documentation to do so.
This is the code where I generate the docx file:
class OperationDOCXView(viewsets.ViewSet):
exclude_from_schema = True
def list(self, request):
from ReportsManagerApp.controllers import Operations2Controller
self.profile_id = request.query_params['profile_id']
self.operation_date = request.query_params['operation_date']
self.operation_type = request.query_params['operation_type']
self.format = request.query_params['doc_format']
operation_report_controller = Operations2Controller(self.profile_id, self.operation_date, self.operation_type)
context = operation_report_controller.get_context()
if self.format == 'json':
return Response(context)
else:
word_doc = self.get_operation_word_file(request, context)
return Response("{}{}{}".format(request.get_host(), settings.MEDIA_URL, word_doc))
def get_operation_word_file(self, request, context):
import unicodedata
from django.core.files import File
from django.urls import reverse
from docx import Document
from docx.shared import Inches, Pt
operation_type = {
'arrival': 'Llegadas',
'departure': 'Salidas',
'hotel': 'Hotel-Hotel',
'tour': 'Tours',
}
weekdays = {
'0': 'LUNES',
'1': 'MARTES',
'2': 'MIÉRCOLES',
'3': 'JUEVES',
'4': 'VIERNES',
'5': 'SÁBADO',
'6': 'DOMINGO',
}
titles = ['Booking', 'Nombre', '#', 'Vuelo', 'Hr', 'P Up', 'Traslado', 'Circuito', 'Priv?', 'Agencia', '']
widths = [Inches(1), Inches(2), Inches(0.5), Inches(1), Inches(1), Inches(1), Inches(2), Inches(3), Inches(0.5), Inches(3), Inches(0.5)]
document = Document()
section = document.sections[-1]
section.top_margin = Inches(0.5)
section.bottom_margin = Inches(0.5)
section.left_margin = Inches(0.3)
section.right_margin = Inches(0.2)
style = document.styles['Normal']
font = style.font
font.name ='Arial'
font.size = Pt(10)
company_paragraph = document.add_heading("XXXX TTOO INC")
company_paragraph.alignment = WD_ALIGN_PARAGRAPH.CENTER
description_paragraph = document.add_paragraph("Operación de {} del día {}".format(operation_type[self.operation_type], self.operation_date))
description_paragraph.alignment = WD_ALIGN_PARAGRAPH.CENTER
operation_date = self.get_operation_date().date()
operation_week_day = operation_date.weekday()
day_paragraph = document.add_paragraph(weekdays[str(operation_week_day)])
day_paragraph.alignment = WD_ALIGN_PARAGRAPH.CENTER
for provider_unit, transfers in context.items():
provider_unit_paragraph = document.add_paragraph(provider_unit)
provider_unit_paragraph.style.font.size = Pt(10)
provider_unit_paragraph.style.font.bold = False
table = document.add_table(rows=1, cols=11)
hdr_cells = table.rows[0].cells
runs = []
for i in range(len(hdr_cells)):
runs.append(self.get_hdr_cells_run(hdr_cells[i], titles[i]))
for row in table.rows:
for idx, width in enumerate(widths):
row.cells[idx].width = width
adults = 0
minors = 0
for transfer in transfers:
# table = document.add_table(rows=1, cols=11)
row_cells = table.add_row().cells
row_cells[0].text = transfer['booking']
row_cells[1].text = transfer['people']
row_cells[2].text = transfer['pax']
flight = transfer.get("flight","") if transfer.get("flight","") is not None else ""
row_cells[3].text = flight
flight_time = self.get_flight_time(flight) if flight != '' else ''
row_cells[4].text = flight_time
row_cells[5].text = transfer['pickup_time'].strftime('%H:%M') if transfer['pickup_time'] is not None else ''
row_cells[6].text = transfer['place']
row_cells[7].text = transfer['roundtrip']
row_cells[8].text = transfer['is_private']
row_cells[9].text = transfer['agency']
people = transfer['pax'].split('.')
adults = adults + int(people[0])
minors = minors + int(people[1])
if transfer['comment'] is not None:
document.add_paragraph("Comentarios: {}".format(transfer['comment']))
for row in table.rows:
for idx, width in enumerate(widths):
row.cells[idx].width = width
for cell in row.cells:
paragraphs = cell.paragraphs
for paragraph in paragraphs:
for run in paragraph.runs:
font = run.font
font.size = Pt(8)
row_cells = table.add_row().cells
row_cells[10].text = "{}.{}".format(adults, minors)
current_directory = settings.MEDIA_DIR
file_name = "Operaciones {} {}.docx".format(self.operation_type, self.operation_date)
document.save("{}{}".format(current_directory, file_name))
return file_name
def get_flight_time(self, flight):
from OperationsManagerApp.models import Flight
operation_types = {
'arrival': 'ARRIVAL',
'departure': 'DEPARTURE'
}
operation_date = datetime.strptime(self.operation_date, '%Y-%m-%d')
try:
flight = Flight.objects.get(flight_type=operation_types[self.operation_type], number=flight)
except:
return ''
else:
weekday_times = {
'0': flight.time_monday,
'1': flight.time_tuesday,
'2': flight.time_wednesday,
'3': flight.time_thursday,
'4': flight.time_friday,
'5': flight.time_saturday,
'6': flight.time_sunday,
}
weekday_time = weekday_times[str(operation_date.weekday())]
return weekday_time.strftime('%H:%M') if weekday_time is not None else ''
def get_hdr_cells_run(self, hdr_cells, title):
from docx.shared import Pt
new_run = hdr_cells.paragraphs[0].add_run(title)
new_run.bold = True
new_run.font.size = Pt(8)
return new_run
def get_operation_date(self):
date_array = self.operation_date.split('-')
day = int(date_array[2])
month = int(date_array[1])
year = int(date_array[0])
operation_date = datetime(year, month, day)
return operation_date
One approach is to add a paragraph to one of the cells:
cell.add_paragraph(transfer['comment'])
This will place it in the right position with respect to the row it belongs to, rather than after the table.
If that would take too much room for a single cell that already has another data item in it and you want to add a row, you'll need to account for that when you allocate the table. But assuming you get that worked out, merging the cells is easy:
row.cells[0].merge(row.cells[-1])